├── .gitignore
├── BmobTest
├── BmobTask.cs
├── BmobTest.csproj
├── BmobTestBase.cs
├── GameObject.cs
├── Properties
│ └── AssemblyInfo.cs
├── SimpleTest.cs
└── alpha.orderedtest
├── LICENSE
├── README.md
├── build.simple.bat
└── core
├── BmobCore.Desktop.csproj
├── BmobCore.Unity.csproj
├── BmobCore.WP8.csproj
├── BmobCore.Win8_1.csproj
├── Properties
└── AssemblyInfo.cs
└── src
├── Extensions
├── BmobObjectExtension.cs
└── MiscExtensions.cs
├── HelloBmob.cs
├── api
├── Bmob.OO.cs
├── Bmob.Task.cs
├── Bmob.cs
├── BmobUnity.cs
├── BmobWindows.cs
├── BmobWindowsPhone.cs
└── IBmobAPI.cs
├── config
└── Configuration.cs
├── example
└── GameObject.cs
├── exception
└── BmobException.cs
├── http
├── BmobCommand.cs
├── BmobInteractionObject.cs
└── Http.cs
├── io
├── BmobACL.cs
├── BmobDate.cs
├── BmobFile.cs
├── BmobGeoPoint.cs
├── BmobInput.cs
├── BmobInstallation.cs
├── BmobKV.cs
├── BmobObject.cs
├── BmobOutput.cs
├── BmobPointer.cs
├── BmobQuery.cs
├── BmobRelation.cs
├── BmobRole.cs
├── BmobTable.cs
├── BmobTable2.cs
├── BmobUser.cs
├── IBmobOperator.cs
├── IBmobValue.cs
├── IBmobWritable.cs
├── basic
│ ├── BmobBoolean.cs
│ ├── BmobDouble.cs
│ ├── BmobInt.cs
│ ├── BmobLong.cs
│ └── BmobNumber.cs
├── operator
│ ├── Add.cs
│ ├── AddRelation.cs
│ ├── AddUnique.cs
│ ├── Delete.cs
│ ├── Increment.cs
│ ├── Operate.cs
│ ├── Remove.cs
│ └── RemoveRelation.cs
└── paramater
│ ├── BmobBatch.cs
│ ├── BmobLocalFile.cs
│ ├── BmobRemote.cs
│ ├── PushParamter.cs
│ ├── SMSParamter.cs
│ └── ThumbnailParameter.cs
├── json
├── JsonAdapter.cs
├── SimpleJson.cs
└── SimpleJsonParser.cs
├── response
├── BmobResponseParser.cs
├── Create.cs
├── Delete.cs
├── Empty.cs
├── EndPoint.cs
├── Query.cs
├── SMS.cs
├── Status.cs
├── TimeStamp.cs
├── Update.cs
└── Upload.cs
└── tools
├── BmobArrays.cs
├── BmobDebug.cs
└── Utilities.cs
/.gitignore:
--------------------------------------------------------------------------------
1 | [Ll]ibrary/
2 | [Tt]emp/
3 | [Oo]bj/
4 | [Bb]uild/
5 |
6 | # Autogenerated VS/MD solution and project files
7 | #*.csproj
8 | #*.unityproj
9 | *.sln
10 | *.suo
11 | *.tmp
12 | *.user
13 | *.userprefs
14 | *.pidb
15 | *.booproj
16 |
17 | # Unity3D generated meta files
18 | *.pidb.meta
19 |
20 | # Unity3D Generated File On Crash Reports
21 | sysinfo.txt
22 |
23 | ##
24 | *.log
25 | .vs
26 | bin
27 | target
28 | TestResults
29 | bmob-demo-csharp
30 |
--------------------------------------------------------------------------------
/BmobTest/BmobTest.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | {E43B2230-DDC0-4FF6-95D2-37C4EDFF8812}
7 | Library
8 | Properties
9 | BmobTest
10 | BmobTest
11 | v4.5
12 | 512
13 | {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
14 | 10.0
15 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
16 | $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages
17 | False
18 | UnitTest
19 |
20 |
21 |
22 | true
23 | full
24 | false
25 | bin\Debug\
26 | DEBUG;TRACE
27 | prompt
28 | 4
29 | false
30 |
31 |
32 | pdbonly
33 | true
34 | bin\Release\
35 | TRACE
36 | prompt
37 | 4
38 | false
39 |
40 |
41 |
42 |
43 | 3.5
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 | {5da85313-cd98-4998-a882-5002fa2ef6e2}
68 | BmobCore
69 |
70 |
71 |
72 |
73 |
74 |
75 | False
76 |
77 |
78 | False
79 |
80 |
81 | False
82 |
83 |
84 | False
85 |
86 |
87 |
88 |
89 |
90 |
91 |
98 |
--------------------------------------------------------------------------------
/BmobTest/BmobTestBase.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Diagnostics;
6 | using System.Threading;
7 | using Microsoft.VisualStudio.TestTools.UnitTesting;
8 | using System.IO;
9 | using cn.bmob.io;
10 | using cn.bmob.json;
11 | using cn.bmob.tools;
12 | using cn.bmob.exception;
13 |
14 | using cn.bmob.api;
15 |
16 | namespace cn.bmob.api.unit
17 | {
18 |
19 | public abstract class BmobTestBase : BmobObject
20 | {
21 |
22 | protected static BmobWindows Bmob = new BmobWindows();
23 |
24 | private static String LatestObjectIdFile = System.IO.Path.GetTempPath() + "/BmobTest_LatestObjectId";
25 | public static String LatestObjectId
26 | {
27 | get
28 | {
29 | using (var sr = new StreamReader(LatestObjectIdFile))
30 | {
31 | return sr.ReadToEnd();
32 | }
33 | }
34 | set
35 | {
36 | using (var sw = new StreamWriter(LatestObjectIdFile))
37 | {
38 | sw.Write(value);
39 | }
40 |
41 | }
42 | }
43 | private static String LatestSessionTokenFile = System.IO.Path.GetTempPath() + "/BmobTest_LatestSessionToken";
44 | public static String LatestSessionToken
45 | {
46 | get
47 | {
48 | using (var sr = new StreamReader(LatestSessionTokenFile))
49 | {
50 | return sr.ReadToEnd();
51 | }
52 | }
53 | set
54 | {
55 | using (var sw = new StreamWriter(LatestSessionTokenFile))
56 | {
57 | sw.Write(value);
58 | }
59 |
60 | }
61 | }
62 |
63 | static BmobTestBase()
64 | {
65 | Bmob.initialize("4414150cb439afdf684d37dc184e0f9f", "e1deb317442129c125b228ddf78e5f22");
66 | BmobDebug.Register(msg => { Debug.WriteLine(msg); });
67 | BmobDebug.level = BmobDebug.Level.TRACE;
68 | }
69 |
70 | public virtual void FinishedCallback(T resp, BmobException ex)
71 | {
72 | if (resp != null)
73 | {
74 | var pObjectId = resp.GetType().GetProperty("objectId");
75 | if (pObjectId != null)
76 | {
77 | var value = (String)pObjectId.GetValue(resp, null);
78 | if (!Utilities.Empty(value))
79 | LatestObjectId = value;
80 | }
81 |
82 | var pSessionToken = resp.GetType().GetProperty("sessionToken");
83 | if (pSessionToken != null)
84 | {
85 | var value = (String)pSessionToken.GetValue(resp, null);
86 | if (!Utilities.Empty(value))
87 | LatestSessionToken = value;
88 | }
89 | }
90 |
91 | Console.WriteLine();
92 | Console.WriteLine("\n返回结果打印输出(用户可以获取的数据): " + JsonAdapter.JSON.ToDebugJsonString(resp) );
93 | Console.WriteLine("\n返回结果: " + JsonAdapter.JSON.ToDebugJsonString(resp));
94 | Console.WriteLine("\n返回结果异常信息输出: " + ex);
95 |
96 | if (ex != null)
97 | {
98 | Assert.Fail(ex.Message);
99 | }
100 |
101 | }
102 |
103 | public String toJson(IBmobWritable data)
104 | {
105 | return ToString(data);
106 | }
107 |
108 | }
109 |
110 | public abstract class WaitRequestFinishTest : BmobTestBase
111 | {
112 |
113 | // http://club.sm160.com/showtopic-886147.aspx
114 | public static ManualResetEvent WaitUnitFinish = new ManualResetEvent(false);
115 |
116 | public static void releaseLock()
117 | {
118 | WaitUnitFinish.Set();
119 | }
120 |
121 | //~WaitRequestFinishTest()
122 | //{
123 | // WaitUnitFinish.Close();
124 | //}
125 |
126 | public override void FinishedCallback(T resp, BmobException ex)
127 | {
128 | try
129 | {
130 | base.FinishedCallback(resp, ex);
131 | }
132 | finally
133 | {
134 | releaseLock();
135 | }
136 | }
137 |
138 | #region 附加测试特性
139 | //
140 | //使用 TestInitialize 在运行每个测试前先运行代码
141 | public virtual void setup()
142 | {
143 | WaitUnitFinish.Reset();
144 | }
145 | //
146 | //使用 TestCleanup 在运行完每个测试后运行代码
147 | public virtual void teardown()
148 | {
149 | WaitUnitFinish.WaitOne();
150 | }
151 | //
152 | #endregion
153 | }
154 | }
155 |
--------------------------------------------------------------------------------
/BmobTest/GameObject.cs:
--------------------------------------------------------------------------------
1 | using cn.bmob.io;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | namespace cn.bmob.api.unit
9 | {
10 | public class GameObject : BmobTable
11 | {
12 | public override string table
13 | {
14 | get
15 | {
16 | if (fTable != null)
17 | {
18 | return fTable;
19 | }
20 | return base.table;
21 | }
22 | }
23 |
24 | private String fTable;
25 | public GameObject() { }
26 |
27 | public GameObject(string table)
28 | {
29 | this.fTable = table;
30 | }
31 |
32 | public List arrint { get; set; }
33 | public List arrstring { get; set; }
34 | public BmobInt jo { get; set; }
35 | public BmobInt jo2 { get; set; }
36 | public BmobInt obj { get; set; }
37 | public string s { get; set; }
38 |
39 | public BmobPointer user { get; set; }
40 |
41 | public override void readFields(BmobInput input)
42 | {
43 | base.readFields(input);
44 |
45 | this.arrint = input.getList("arrint");
46 | this.arrstring = input.getList("arrstring");
47 | this.jo = input.getInt("jo");
48 | this.jo2 = input.getInt("jo2");
49 | this.obj = input.getInt("obj");
50 | this.s = input.getString("s");
51 |
52 |
53 | this.user = input.Get>("user");
54 | }
55 |
56 | public override void write(BmobOutput output, Boolean all)
57 | {
58 | base.write(output, all);
59 |
60 | output.Put("arrint", this.arrint);
61 | output.Put("arrstring", this.arrstring);
62 |
63 | output.Put("jo", this.jo);
64 | output.Put("jo2", this.jo2);
65 | output.Put("obj", this.obj);
66 | output.Put("s", this.s);
67 |
68 | output.Put("user", this.user);
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/BmobTest/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // 有关程序集的常规信息通过以下特性集
6 | // 控制。更改这些特性值可修改
7 | // 与程序集关联的信息。
8 | [assembly: AssemblyTitle("BmobTest")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("BmobTest")]
13 | [assembly: AssemblyCopyright("Copyright © 2015")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // 将 ComVisible 设置为 false 会使此程序集中的类型
18 | // 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型,
19 | // 请将该类型上的 ComVisible 特性设置为 true。
20 | [assembly: ComVisible(false)]
21 |
22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
23 | [assembly: Guid("e43b2230-ddc0-4ff6-95d2-37c4edff8812")]
24 |
25 | // 程序集的版本信息由以下四个值组成:
26 | //
27 | // 主版本
28 | // 次版本
29 | // 生成号
30 | // 修订号
31 | //
32 | // 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
33 | // 方法是按如下所示使用“*”:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/BmobTest/SimpleTest.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Microsoft.VisualStudio.TestTools.UnitTesting;
3 | using cn.bmob.io;
4 | using System.Text.RegularExpressions;
5 |
6 | namespace BmobTest
7 | {
8 | [TestClass]
9 | public class SimpleTest
10 | {
11 |
12 | [TestMethod()]
13 | public void BmobDateTest()
14 | {
15 | BmobDate d = DateTime.Now;
16 | Console.WriteLine(d);
17 | }
18 |
19 | [TestMethod()]
20 | public void RegexTest()
21 | {
22 | var ss = "HTTP/1.1 400 abc.txt";
23 | ss = Regex.Replace(ss, @"[^ ]* (\d*) .*", "$1");
24 | Console.WriteLine(ss);
25 | }
26 |
27 | [TestMethod()]
28 | public void BmobIntTest()
29 | {
30 | // set
31 | BmobInt i = new BmobInt(1);
32 | BmobInt i2 = 1; // 有隐士转换
33 |
34 | // get
35 | int iv = i.Get();
36 | }
37 |
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/BmobTest/alpha.orderedtest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # BmobSharp
2 |
3 | Bmob Api Client for .Net
4 |
5 | ## Bmob C# SDK下载地址:
6 |
7 |
8 |
9 | ## 支持平台
10 |
11 | * Windows Deskstop 即.Net C#的项目
12 | * WindowsPhone8
13 | * Windows 8.1
14 | * Unity
15 |
16 | ## 示例
17 |
18 | 参见[bmob-demo-csharp](https://github.com/bmob/bmob-demo-csharp),examples目录下三个项目windows-destop、unity、windowphone8简单介绍了Bmob的基本功能,是了解bmob和学习bmob的不二之选。
19 |
20 | ## 文档
21 |
22 | 源代码中注释比较少,如果对源码中功能弄的不是很明白,查看[文档](https://github.com/bmob/bmob-demo-csharp/wiki)对理解代码和使用有更深的认识。
23 |
24 | *
25 |
26 | ## 开发环境搭建
27 |
28 | * 软件下载/安装
29 |
30 | * [Visual Studio Community 2015](https://www.visualstudio.com/zh-cn/visual-studio-homepage-vs.aspx)
31 | * [Unity3d](http://unity3d.com/cn/get-unity/download?ref=personal)
32 |
33 | * 开发环境说明
34 |
35 | * Window10 / VS2015 / Unity 5.1.0f3
36 | * Mac OS X 10.9 / Xcode 5.1 / Unity 5.2.1f1
37 |
38 | 如果仅仅是编译项目,可以不需要安装Unity3d,下载Unity3d的Engine和Editor动态链接库文件就行了。
39 |
40 |
41 | * 文件结构说明
42 |
43 | * core 全部源代码放在这个目录下。直接运行csproj就可以编辑运行代码了。
44 | * BmobTest 提供了基于desktop平台的测试用例,便于接口的调试。
45 | * 源码中提供了**build.simple.bat**用于一键生成各个平台的dll文件。
46 |
47 | * Unity源码调试设置
48 |
49 | * 删除原来的`Assets/libs/Bmob-Unity.dll`。
50 | * 把源代码`core/src`目录拷贝到`Assets/classes/`下。
51 | * 打开Unity重新编译,把BmobUntiy对象拖拽到摄像机上,重新设置AppId和RestKey。
52 | 
53 |
54 | * Unity输出日志位置:
55 |
56 | * Unity Mac环境配置
57 |
58 | 
59 |
60 | 
61 |
62 | 
63 |
64 | ## 注意事项
65 |
66 | ### 文件/图片无法上传的问题
67 |
68 | - 直接使用源码,不要用dll文件
69 | - 也可以在原来源码基础上,修改[Configuration.cs](`https://github.com/bmob/BmobSharp/blob/master/core/src/config/Configuration.cs`) 文件为最新版
70 |
71 |
72 | ### Bmob Vip域名加速服务
73 |
74 | - 修改[Configuration.cs](`https://github.com/bmob/BmobSharp/blob/master/core/src/config/Configuration.cs`) 文件
75 |
76 | ### Bmob Vip域名加速服务
77 |
78 | 2022年支持重置域名,Bmob.resetDomain("http://api.xxx.com"); 初始化前修改未自己备案api域名。
79 |
80 | ### 兼容Unity2017、2018的问题
81 |
82 | - 直接使用源码,不要用dll文件
83 |
--------------------------------------------------------------------------------
/build.simple.bat:
--------------------------------------------------------------------------------
1 | @echo on
2 |
3 | set config=%1
4 | if "%config%" == "" (
5 | set config=Release
6 | )
7 |
8 | REM Build
9 | %WINDIR%\Microsoft.NET\Framework\v4.0.30319\msbuild.exe core/BmobCore.Desktop.csproj /p:Configuration=%config% /m /v:M /fl /flp:LogFile=msbuild.Desktop.log;Verbosity=Normal /nr:true /p:BuildInParallel=true /p:RestorePackages=true /t:Clean,Rebuild
10 | if not "%errorlevel%"=="0" goto failure
11 |
12 | %WINDIR%\Microsoft.NET\Framework\v4.0.30319\msbuild.exe core/BmobCore.Unity.csproj /p:Configuration=%config% /m /v:M /fl /flp:LogFile=msbuild.Unity.log;Verbosity=Normal /nr:true /p:BuildInParallel=true /p:RestorePackages=true /t:Clean,Rebuild
13 | if not "%errorlevel%"=="0" goto failure
14 |
15 | %WINDIR%\Microsoft.NET\Framework\v4.0.30319\msbuild.exe core/BmobCore.Win8_1.csproj /p:Configuration=%config% /m /v:M /fl /flp:LogFile=msbuild.Win8_1.log;Verbosity=Normal /nr:true /p:BuildInParallel=true /p:RestorePackages=true /t:Clean,Rebuild
16 | if not "%errorlevel%"=="0" goto failure
17 |
18 | REM 没有安装wp8 SDK了
19 | REM %WINDIR%\Microsoft.NET\Framework\v4.0.30319\msbuild.exe core/BmobCore.WP8.csproj /p:Configuration=%config% /m /v:M /fl /flp:LogFile=msbuild.WP8.log;Verbosity=Normal /nr:true /p:BuildInParallel=true /p:RestorePackages=true /t:Clean,Rebuild
20 | REM if not "%errorlevel%"=="0" goto failure
21 |
22 | REM delete the old stuff
23 |
24 | rd target /s /q
25 | rd bmob-demo-csharp\examples\bmob-desktop-demo\lib\ /s /q
26 | rd bmob-demo-csharp\examples\bmob-unity-demo\Assets\libs /s /q
27 | rd bmob-demo-csharp\examples\bmob-windowsphone-demo\lib\ /s /q
28 |
29 | if not exist target\Unity mkdir target\Unity\
30 | if not exist target\Windows mkdir target\Windows\
31 | if not exist target\WindowsPhone8 mkdir target\WindowsPhone8\
32 | if not exist target\Win8_1 mkdir target\Win8_1\
33 |
34 | if not exist bmob-demo-csharp\examples\bmob-desktop-demo\lib\ mkdir bmob-demo-csharp\examples\bmob-desktop-demo\lib\
35 | if not exist bmob-demo-csharp\examples\bmob-unity-demo\Assets\libs mkdir bmob-demo-csharp\examples\bmob-unity-demo\Assets\libs
36 | if not exist bmob-demo-csharp\examples\bmob-windowsphone-demo\lib\ mkdir bmob-demo-csharp\examples\bmob-windowsphone-demo\lib\
37 |
38 | rem unity
39 |
40 | copy Core\bin\Release\Bmob-Unity.dll target\Unity\
41 |
42 | copy Core\bin\Release\Bmob-Unity.XML target\Unity
43 |
44 | rem desktop
45 |
46 | copy Core\bin\Release\Bmob-Windows.dll target\Windows\
47 |
48 | copy Core\bin\Release\Bmob-Windows.XML target\Windows\
49 |
50 | rem wp8
51 |
52 | copy Core\bin\Release\Bmob-WP8.dll target\WindowsPhone8\
53 |
54 | copy Core\bin\Release\Bmob-WP8.XML target\WindowsPhone8\
55 |
56 | rem win8_1
57 |
58 | copy Core\bin\Release\Bmob-Win8_1.dll target\Win8_1\
59 |
60 | copy Core\bin\Release\Bmob-Win8_1.XML target\Win8_1\
61 |
62 | copy Core\bin\Release\Bmob-Unity.dll bmob-demo-csharp\examples\bmob-unity-demo\Assets\libs\
63 | copy Core\bin\Release\Bmob-WP8.dll bmob-demo-csharp\examples\bmob-windowsphone-demo\lib\
64 | copy Core\bin\Release\Bmob-Windows.dll bmob-demo-csharp\examples\bmob-desktop-demo\lib\
65 |
66 | :success
67 |
68 | REM compile success
69 |
70 | goto end
71 |
72 | :failure
73 |
74 | REM compile fail
75 |
76 | goto end
77 |
78 | :end
79 |
80 | pause
--------------------------------------------------------------------------------
/core/BmobCore.Desktop.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {5DA85313-CD98-4998-A882-5002FA2EF6E2}
8 | Library
9 | Properties
10 | cn.bmob
11 | Bmob-Windows
12 | v4.0
13 | 512
14 |
15 |
16 |
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | TRACE;DEBUG;FRAMEWORK,NET4
22 | prompt
23 | 4
24 |
25 |
26 | pdbonly
27 | true
28 | bin\Release\
29 | TRACE;FRAMEWORK,NET4
30 | prompt
31 | 4
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 | Code
45 |
46 |
47 | Code
48 |
49 |
50 | Code
51 |
52 |
53 | Code
54 |
55 |
56 | Code
57 |
58 |
59 |
60 | Code
61 |
62 |
63 | Code
64 |
65 |
66 | Code
67 |
68 |
69 | Code
70 |
71 |
72 |
73 |
74 | Code
75 |
76 |
77 | Code
78 |
79 |
80 | Code
81 |
82 |
83 | Code
84 |
85 |
86 | Code
87 |
88 |
89 | Code
90 |
91 |
92 | Code
93 |
94 |
95 | Code
96 |
97 |
98 | Code
99 |
100 |
101 | Code
102 |
103 |
104 | Code
105 |
106 |
107 | Code
108 |
109 |
110 |
111 | Code
112 |
113 |
114 | Code
115 |
116 |
117 | Code
118 |
119 |
120 | Code
121 |
122 |
123 | Code
124 |
125 |
126 | Code
127 |
128 |
129 | Code
130 |
131 |
132 | Code
133 |
134 |
135 |
136 | Code
137 |
138 |
139 | Code
140 |
141 |
142 | Code
143 |
144 |
145 | Code
146 |
147 |
148 | Code
149 |
150 |
151 | Code
152 |
153 |
154 | Code
155 |
156 |
157 | Code
158 |
159 |
160 | Code
161 |
162 |
163 | Code
164 |
165 |
166 | Code
167 |
168 |
169 |
170 |
171 | Code
172 |
173 |
174 |
175 |
176 | Code
177 |
178 |
179 | Code
180 |
181 |
182 |
183 |
184 |
185 | Code
186 |
187 |
188 | Code
189 |
190 |
191 | Code
192 |
193 |
194 | Code
195 |
196 |
197 | Code
198 |
199 |
200 | Code
201 |
202 |
203 | Code
204 |
205 |
206 |
207 |
208 | Code
209 |
210 |
211 | Code
212 |
213 |
214 | Code
215 |
216 |
217 | Code
218 |
219 |
220 | Code
221 |
222 |
223 |
224 |
231 |
--------------------------------------------------------------------------------
/core/BmobCore.Unity.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | 8.0.30703
7 | 2.0
8 | {BE007CD7-75A3-4839-A074-6A9732CB7CA4}
9 | Library
10 | Properties
11 | cn.bmob
12 | Bmob-Unity
13 | v3.5
14 | 512
15 |
16 |
17 | True
18 | full
19 | False
20 | bin\Debug\
21 | TRACE;DEBUG;Unity
22 | prompt
23 | 4
24 |
25 |
26 | pdbonly
27 | True
28 | bin\Release\
29 | TRACE;Unity
30 | prompt
31 | 4
32 | bin\Release\Bmob-Unity.XML
33 |
34 |
35 |
36 |
37 |
38 | C:\Program Files\Unity\Editor\Data\Managed\UnityEditor.dll
39 |
40 |
41 | C:\Program Files\Unity\Editor\Data\Managed\UnityEngine.dll
42 |
43 |
44 |
45 |
46 | Code
47 |
48 |
49 | Code
50 |
51 |
52 | Code
53 |
54 |
55 | Code
56 |
57 |
58 | Code
59 |
60 |
61 |
62 | Code
63 |
64 |
65 | Code
66 |
67 |
68 | Code
69 |
70 |
71 | Code
72 |
73 |
74 |
75 |
76 | Code
77 |
78 |
79 | Code
80 |
81 |
82 | Code
83 |
84 |
85 | Code
86 |
87 |
88 | Code
89 |
90 |
91 | Code
92 |
93 |
94 | Code
95 |
96 |
97 | Code
98 |
99 |
100 | Code
101 |
102 |
103 | Code
104 |
105 |
106 | Code
107 |
108 |
109 | Code
110 |
111 |
112 |
113 | Code
114 |
115 |
116 | Code
117 |
118 |
119 | Code
120 |
121 |
122 | Code
123 |
124 |
125 | Code
126 |
127 |
128 | Code
129 |
130 |
131 | Code
132 |
133 |
134 | Code
135 |
136 |
137 |
138 | Code
139 |
140 |
141 | Code
142 |
143 |
144 | Code
145 |
146 |
147 | Code
148 |
149 |
150 | Code
151 |
152 |
153 | Code
154 |
155 |
156 | Code
157 |
158 |
159 | Code
160 |
161 |
162 | Code
163 |
164 |
165 | Code
166 |
167 |
168 | Code
169 |
170 |
171 |
172 |
173 | Code
174 |
175 |
176 |
177 |
178 | Code
179 |
180 |
181 | Code
182 |
183 |
184 |
185 |
186 |
187 | Code
188 |
189 |
190 | Code
191 |
192 |
193 | Code
194 |
195 |
196 | Code
197 |
198 |
199 | Code
200 |
201 |
202 | Code
203 |
204 |
205 | Code
206 |
207 |
208 |
209 |
210 | Code
211 |
212 |
213 | Code
214 |
215 |
216 | Code
217 |
218 |
219 | Code
220 |
221 |
222 | Code
223 |
224 |
225 |
226 |
233 |
--------------------------------------------------------------------------------
/core/BmobCore.WP8.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | 10.0.20506
7 | 2.0
8 | {5148698C-E455-4B0B-9AB6-42A8BA8775EB}
9 | {C089C8C0-30E0-4E22-80C0-CE093F111A43};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}
10 | Library
11 | Properties
12 | cn.bmob
13 | Bmob-WP8
14 | WindowsPhone
15 | v8.0
16 | $(TargetFrameworkVersion)
17 | false
18 | true
19 | 11.0
20 | true
21 |
22 |
23 | true
24 | full
25 | false
26 | Bin\Debug
27 | TRACE;DEBUG;SILVERLIGHT;WINDOWS_PHONE;WP8
28 | true
29 | true
30 | prompt
31 | 4
32 |
33 |
34 |
35 |
36 | pdbonly
37 | true
38 | Bin\Release
39 | TRACE;SILVERLIGHT;WINDOWS_PHONE;WP8
40 | true
41 | true
42 | prompt
43 | 4
44 | Bin\Release\Bmob-WP8.XML
45 |
46 |
47 | true
48 | full
49 | false
50 | Bin\x86\Debug
51 | DEBUG;TRACE;SILVERLIGHT;WINDOWS_PHONE
52 | true
53 | true
54 | prompt
55 | 4
56 |
57 |
58 | pdbonly
59 | true
60 | Bin\x86\Release
61 | TRACE;SILVERLIGHT;WINDOWS_PHONE
62 | true
63 | true
64 | prompt
65 | 4
66 |
67 |
68 | true
69 | full
70 | false
71 | Bin\ARM\Debug
72 | DEBUG;TRACE;SILVERLIGHT;WINDOWS_PHONE
73 | true
74 | true
75 | prompt
76 | 4
77 |
78 |
79 | pdbonly
80 | true
81 | Bin\ARM\Release
82 | TRACE;SILVERLIGHT;WINDOWS_PHONE
83 | true
84 | true
85 | prompt
86 | 4
87 |
88 |
89 |
90 |
91 | Code
92 |
93 |
94 | Code
95 |
96 |
97 | Code
98 |
99 |
100 | Code
101 |
102 |
103 | Code
104 |
105 |
106 |
107 | Code
108 |
109 |
110 | Code
111 |
112 |
113 | Code
114 |
115 |
116 | Code
117 |
118 |
119 |
120 |
121 | Code
122 |
123 |
124 | Code
125 |
126 |
127 | Code
128 |
129 |
130 | Code
131 |
132 |
133 | Code
134 |
135 |
136 | Code
137 |
138 |
139 | Code
140 |
141 |
142 | Code
143 |
144 |
145 | Code
146 |
147 |
148 | Code
149 |
150 |
151 | Code
152 |
153 |
154 | Code
155 |
156 |
157 |
158 | Code
159 |
160 |
161 | Code
162 |
163 |
164 | Code
165 |
166 |
167 | Code
168 |
169 |
170 | Code
171 |
172 |
173 | Code
174 |
175 |
176 | Code
177 |
178 |
179 | Code
180 |
181 |
182 |
183 | Code
184 |
185 |
186 | Code
187 |
188 |
189 | Code
190 |
191 |
192 | Code
193 |
194 |
195 | Code
196 |
197 |
198 | Code
199 |
200 |
201 | Code
202 |
203 |
204 | Code
205 |
206 |
207 | Code
208 |
209 |
210 | Code
211 |
212 |
213 | Code
214 |
215 |
216 |
217 |
218 | Code
219 |
220 |
221 |
222 |
223 | Code
224 |
225 |
226 | Code
227 |
228 |
229 |
230 |
231 |
232 | Code
233 |
234 |
235 | Code
236 |
237 |
238 | Code
239 |
240 |
241 | Code
242 |
243 |
244 | Code
245 |
246 |
247 | Code
248 |
249 |
250 | Code
251 |
252 |
253 |
254 |
255 | Code
256 |
257 |
258 | Code
259 |
260 |
261 | Code
262 |
263 |
264 | Code
265 |
266 |
267 | Code
268 |
269 |
270 |
271 |
272 |
273 |
280 |
--------------------------------------------------------------------------------
/core/BmobCore.Win8_1.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 12.0
6 | Debug
7 | AnyCPU
8 | {2A2610D3-DA6D-4F15-BF4A-B57B85FED05C}
9 | Library
10 | Properties
11 | cn.bmob
12 | Bmob-Win8_1
13 | zh-CN
14 | 512
15 | {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
16 | Profile32
17 | v4.6
18 |
19 |
20 | true
21 | full
22 | false
23 | bin\Debug\
24 | TRACE;DEBUG;NETFX_CORE;WINDOWS_UAP;FRAMEWORK;WIN8_1
25 | prompt
26 | 4
27 |
28 |
29 | pdbonly
30 | true
31 | bin\Release\
32 | TRACE;NETFX_CORE;WINDOWS_UAP;FRAMEWORK;WIN8_1
33 | prompt
34 | 4
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 | Code
46 |
47 |
48 | Code
49 |
50 |
51 | Code
52 |
53 |
54 | Code
55 |
56 |
57 | Code
58 |
59 |
60 |
61 | Code
62 |
63 |
64 | Code
65 |
66 |
67 | Code
68 |
69 |
70 | Code
71 |
72 |
73 |
74 |
75 | Code
76 |
77 |
78 | Code
79 |
80 |
81 | Code
82 |
83 |
84 | Code
85 |
86 |
87 | Code
88 |
89 |
90 | Code
91 |
92 |
93 | Code
94 |
95 |
96 | Code
97 |
98 |
99 | Code
100 |
101 |
102 | Code
103 |
104 |
105 | Code
106 |
107 |
108 | Code
109 |
110 |
111 |
112 | Code
113 |
114 |
115 | Code
116 |
117 |
118 | Code
119 |
120 |
121 | Code
122 |
123 |
124 | Code
125 |
126 |
127 | Code
128 |
129 |
130 | Code
131 |
132 |
133 | Code
134 |
135 |
136 |
137 | Code
138 |
139 |
140 | Code
141 |
142 |
143 | Code
144 |
145 |
146 | Code
147 |
148 |
149 | Code
150 |
151 |
152 | Code
153 |
154 |
155 | Code
156 |
157 |
158 | Code
159 |
160 |
161 | Code
162 |
163 |
164 | Code
165 |
166 |
167 | Code
168 |
169 |
170 |
171 |
172 | Code
173 |
174 |
175 |
176 |
177 | Code
178 |
179 |
180 | Code
181 |
182 |
183 |
184 |
185 |
186 | Code
187 |
188 |
189 | Code
190 |
191 |
192 | Code
193 |
194 |
195 | Code
196 |
197 |
198 | Code
199 |
200 |
201 | Code
202 |
203 |
204 | Code
205 |
206 |
207 |
208 |
209 | Code
210 |
211 |
212 | Code
213 |
214 |
215 | Code
216 |
217 |
218 | Code
219 |
220 |
221 | Code
222 |
223 |
224 |
225 |
232 |
--------------------------------------------------------------------------------
/core/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // 有关程序集的常规信息通过以下
6 | // 特性集控制。更改这些特性值可修改
7 | // 与程序集关联的信息。
8 | [assembly: AssemblyTitle("Bmob Core")]
9 | [assembly: AssemblyDescription("Bmob CSharp API")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("广州市比目网络科技有限公司")]
12 | [assembly: AssemblyProduct("Bmob SDK")]
13 | [assembly: AssemblyCopyright("Copyright © Bmob 2015")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // 将 ComVisible 设置为 false 使此程序集中的类型
18 | // 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型,
19 | // 则将该类型上的 ComVisible 特性设置为 true。
20 | [assembly: ComVisible(false)]
21 |
22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
23 | [assembly: Guid("5da85313-cd98-4998-a882-5002fa2ef6e2")]
24 |
25 | // 程序集的版本信息由下面四个值组成:
26 | //
27 | // 主版本
28 | // 次版本
29 | // 生成号
30 | // 修订号
31 | //
32 | // 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
33 | // 方法是按如下所示使用“*”:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.5.2.0")]
36 | [assembly: AssemblyFileVersion("1.5.2.0")]
37 |
38 | [assembly: InternalsVisibleTo("BmobTest")]
39 |
--------------------------------------------------------------------------------
/core/src/Extensions/BmobObjectExtension.cs:
--------------------------------------------------------------------------------
1 | /*
2 | using cn.bmob.api;
3 | using cn.bmob.io;
4 | using cn.bmob.response;
5 | using System;
6 | using System.Collections.Generic;
7 | using System.Linq;
8 | using System.Linq.Expressions;
9 | using System.Text;
10 | using System.Threading.Tasks;
11 |
12 | namespace cn.bmob.Extensions
13 | {
14 | public static class BmobObjectExtensions
15 | {
16 | public static Object Select(this BmobObject input)
17 | {
18 | return null;
19 | }
20 |
21 | public static BmobQuery Select(this BmobQuery input)
22 | {
23 | return input;
24 | }
25 |
26 | public static BmobQuery Where(this String input, Expression> predicate)
27 | {
28 | return input;
29 | }
30 |
31 | public static BmobQuery Order(this BmobQuery input)
32 | {
33 | return input;
34 | }
35 | }
36 | }
37 | */
--------------------------------------------------------------------------------
/core/src/Extensions/MiscExtensions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 | using System.Collections.Generic;
4 | using System.IO;
5 | using System.Net;
6 | using System.Text;
7 |
8 | namespace cn.bmob.Extensions
9 | {
10 | ///
11 | /// copy restsharp
12 | ///
13 | public static class MiscExtensions
14 | {
15 | #if WIN8_1
16 | public static void Close(this HttpWebResponse m)
17 | {
18 | m.Dispose();
19 | }
20 |
21 | public static Type[] GetGenericArguments(this Type t)
22 | {
23 | return System.Reflection.IntrospectionExtensions.GetTypeInfo(t).GenericTypeArguments;
24 | }
25 |
26 | public static bool IsAssignableFrom(this Type a, Type b)
27 | {
28 | var at = System.Reflection.IntrospectionExtensions.GetTypeInfo(a);
29 | var bt = System.Reflection.IntrospectionExtensions.GetTypeInfo(b);
30 | return at.IsAssignableFrom(bt);
31 | }
32 | #endif
33 |
34 | public static bool IsGenericType(this Type t)
35 | {
36 | #if WIN8_1
37 | return System.Reflection.IntrospectionExtensions.GetTypeInfo(t).IsGenericType;
38 | #else
39 | return t.IsGenericType;
40 | #endif
41 | }
42 |
43 | ///
44 | /// Read a stream into a byte array
45 | ///
46 | /// Stream to read
47 | /// byte[]
48 | public static byte[] ReadAsBytes(this Stream input)
49 | {
50 | byte[] buffer = new byte[16 * 1024];
51 | using (MemoryStream ms = new MemoryStream())
52 | {
53 | int read;
54 | while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
55 | {
56 | ms.Write(buffer, 0, read);
57 | }
58 | return ms.ToArray();
59 | }
60 | }
61 |
62 | public static byte[] GetBytes(this string s)
63 | {
64 | return Encoding.UTF8.GetBytes(s);
65 | }
66 |
67 | public static String ToBase64(this string s)
68 | {
69 | return Convert.ToBase64String(s.GetBytes());
70 | }
71 |
72 | public static String ToBase64(this byte[] s)
73 | {
74 | return Convert.ToBase64String(s);
75 | }
76 |
77 | public static String FromBase64(this string s)
78 | {
79 | return Convert.FromBase64String(s).AsString();
80 | }
81 |
82 | private static char[] HEX_ALPHA = new char[]{ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
83 | public static String ToHexString(this byte[] src)
84 | {
85 | if (src == null || src.Length <= 0)
86 | {
87 | return null;
88 | }
89 |
90 | StringBuilder sb = new StringBuilder();
91 | for (int i = 0; i < src.Length; i++)
92 | {
93 | sb.Append(HEX_ALPHA[src[i] >> 4 & 0xF]);
94 | sb.Append(HEX_ALPHA[src[i] & 0xF]);
95 | }
96 | return sb.ToString();
97 | }
98 |
99 | ///
100 | /// Converts a byte array to a string, using its byte order mark to convert it to the right encoding.
101 | /// http://www.shrinkrays.net/code-snippets/csharp/an-extension-method-for-converting-a-byte-array-to-a-string.aspx
102 | ///
103 | /// An array of bytes to convert
104 | /// The byte as a string.
105 | public static string AsString(this byte[] buffer)
106 | {
107 | if (buffer == null) return "";
108 |
109 | // UTF8 as default
110 | Encoding encoding = Encoding.UTF8;
111 |
112 | #if FRAMEWORK
113 | return encoding.GetString(buffer, 0, buffer.Length);
114 | #else
115 | if (buffer == null || buffer.Length == 0)
116 | return "";
117 |
118 | /*
119 | EF BB BF UTF-8
120 | FF FE UTF-16 little endian
121 | FE FF UTF-16 big endian
122 | FF FE 00 00 UTF-32, little endian
123 | 00 00 FE FF UTF-32, big-endian
124 | */
125 |
126 | if (buffer[0] == 0xef && buffer[1] == 0xbb && buffer[2] == 0xbf)
127 | {
128 | encoding = Encoding.UTF8;
129 | }
130 | else if (buffer[0] == 0xfe && buffer[1] == 0xff)
131 | {
132 | encoding = Encoding.Unicode;
133 | }
134 | else if (buffer[0] == 0xfe && buffer[1] == 0xff)
135 | {
136 | encoding = Encoding.BigEndianUnicode; // utf-16be
137 | }
138 |
139 | using (MemoryStream stream = new MemoryStream())
140 | {
141 | stream.Write(buffer, 0, buffer.Length);
142 | stream.Seek(0, SeekOrigin.Begin);
143 | using (StreamReader reader = new StreamReader(stream, encoding))
144 | {
145 | return reader.ReadToEnd();
146 | }
147 | }
148 | #endif
149 | }
150 |
151 | ///
152 | /// 将列表连接为字符串,连接符为,号
153 | ///
154 | /// 列表
155 | /// 连接之后的字符串
156 | public static String join(this IList list)
157 | {
158 | return list.join(',');
159 | }
160 |
161 | ///
162 | /// 将列表连接为字符串
163 | ///
164 | /// 列表
165 | /// 连接符
166 | /// 连接之后的字符串
167 | public static String join(this IList list, char separator)
168 | {
169 | StringBuilder result = new StringBuilder();
170 |
171 | bool first = true;
172 | foreach (object ele in list)
173 | {
174 | if (first)
175 | {
176 | first = false;
177 | }
178 | else
179 | {
180 | result.Append(separator);
181 | }
182 |
183 | result.Append(ele.ToString());
184 | }
185 | return result.ToString();
186 | }
187 |
188 | public static string UrlEncode(this string input)
189 | {
190 | const int maxLength = 32766;
191 | if (input == null)
192 | throw new ArgumentNullException("input");
193 |
194 | if (input.Length <= maxLength)
195 | return Uri.EscapeDataString(input);
196 |
197 | StringBuilder sb = new StringBuilder(input.Length * 2);
198 | int index = 0;
199 | while (index < input.Length)
200 | {
201 | int length = Math.Min(input.Length - index, maxLength);
202 | string subString = input.Substring(index, length);
203 | sb.Append(Uri.EscapeDataString(subString));
204 | index += subString.Length;
205 | }
206 |
207 | return sb.ToString();
208 | }
209 |
210 | }
211 | }
212 |
--------------------------------------------------------------------------------
/core/src/api/Bmob.OO.cs:
--------------------------------------------------------------------------------
1 | using cn.bmob.exception;
2 | using cn.bmob.http;
3 | using cn.bmob.io;
4 | using cn.bmob.response;
5 | using System;
6 | using System.Collections.Generic;
7 |
8 | namespace cn.bmob.api
9 | {
10 | public partial class Bmob
11 | {
12 |
13 |
14 | ///
15 | /// 文件上传
16 | ///
17 | ///
18 | ///
19 | public void FileUpload(String localPath, BmobCallback callback)
20 | {
21 | #if !WIN8_1
22 | this.FileUpload(new BmobLocalFile(localPath), callback);
23 | #else
24 | callback(null, new BmobException("SDK WIN8.1暂不支持该方法!!!"));
25 | #endif
26 | }
27 |
28 | public void RequestSmsCode(string mobilePhoneNumber, BmobCallback callback)
29 | {
30 | this.RequestSmsCode(mobilePhoneNumber, null, callback);
31 | }
32 |
33 | public void Endpoint(String eMethod, BmobCallback> callback)
34 | {
35 | this.Endpoint(eMethod, new Dictionary(), callback);
36 | }
37 |
38 | public void Create(T data, BmobCallback callback) where T : BmobTable
39 | {
40 | this.Create(data.table, data, callback);
41 | }
42 |
43 | public void Get(T data, BmobCallback callback) where T : BmobTable
44 | {
45 | this.Get(data.table, data.objectId, callback);
46 | }
47 |
48 | public void Update(T data, BmobCallback callback) where T : BmobTable
49 | {
50 | this.Update(data.table, data.objectId, data, callback);
51 | }
52 |
53 | public void Delete(T data, BmobCallback callback) where T : BmobTable
54 | {
55 | this.Delete(data.table, data.objectId, callback);
56 | }
57 |
58 | ///
59 | /// 登录
60 | ///
61 | /// 返回内置的BmobUser对象。如果User表中添加了字段,请使用Login泛型调用方式。
62 | public void Login(String username, String pwd, BmobCallback callback)
63 | {
64 | this.Login(username, pwd, callback);
65 | }
66 |
67 | ///
68 | /// 使用默认的BmobUser进行注册。即不添加任何额外的字段情况下使用。
69 | ///
70 | public void Signup(BmobUser user, BmobCallback callback)
71 | {
72 | this.Signup(user, callback);
73 | }
74 |
75 | public void UpdateUser(T data, BmobCallback callback) where T : BmobUser
76 | {
77 | this.UpdateUser(data.objectId, data, data.sessionToken, callback);
78 | }
79 |
80 | public void DeleteUser(T data, BmobCallback callback) where T : BmobUser
81 | {
82 | this.DeleteUser(data.objectId, data.sessionToken, callback);
83 | }
84 |
85 | public void FileDelete(BmobFile file, BmobCallback callback)
86 | {
87 | this.FileDelete(file.url, callback);
88 | }
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/core/src/api/BmobUnity.cs:
--------------------------------------------------------------------------------
1 | #if UNITY_5 || UNITY_4 || UNITY_4_6 || UNITY_2017 || UNITY_2018
2 | #define Unity
3 | #endif
4 |
5 | using System;
6 | using System.Collections.Generic;
7 |
8 | using System.Text;
9 | using System.Collections;
10 | using System.Linq;
11 | using cn.bmob.io;
12 | using cn.bmob.http;
13 | using cn.bmob.config;
14 | using cn.bmob.exception;
15 | using cn.bmob.response;
16 | using System.Text.RegularExpressions;
17 |
18 | #if Unity
19 |
20 | using UnityEngine;
21 | using System.Collections.ObjectModel;
22 | using cn.bmob.tools;
23 |
24 | namespace System
25 | {
26 | //public delegate void Action(T1 arg1, T2 arg2);
27 |
28 | public delegate TResult Func(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6);
29 |
30 | public class AggregateException : Exception
31 | {
32 | //
33 | // Properties
34 | //
35 | public ReadOnlyCollection InnerExceptions
36 | {
37 | get;
38 | private set;
39 | }
40 |
41 | //
42 | // Constructors
43 | //
44 | public AggregateException(IEnumerable innerExceptions)
45 | {
46 | this.InnerExceptions = new ReadOnlyCollection(innerExceptions.ToList());
47 | }
48 |
49 | //
50 | // Methods
51 | //
52 | public AggregateException Flatten()
53 | {
54 | List list = new List();
55 | foreach (Exception current in this.InnerExceptions)
56 | {
57 | AggregateException ex = current as AggregateException;
58 | if (ex != null)
59 | {
60 | list.AddRange(ex.Flatten().InnerExceptions);
61 | }
62 | else
63 | {
64 | list.Add(current);
65 | }
66 | }
67 | return new AggregateException(list);
68 | }
69 |
70 | public override string ToString()
71 | {
72 | StringBuilder stringBuilder = new StringBuilder(base.ToString());
73 | foreach (Exception current in this.InnerExceptions)
74 | {
75 | stringBuilder.AppendLine("\n-----------------");
76 | stringBuilder.AppendLine(current.ToString());
77 | }
78 | return stringBuilder.ToString();
79 | }
80 | }
81 |
82 | namespace Threading
83 | {
84 | namespace Tasks
85 | {
86 | }
87 | }
88 |
89 | }
90 |
91 |
92 | namespace cn.bmob.api
93 | {
94 |
95 | public partial class Bmob : MonoBehaviour
96 | {
97 | }
98 |
99 | ///
100 | /// Bmob SDK入口类,开发者直接调用该类即可获取Bmob提供的各种服务。
101 | ///
102 | public class BmobUnity : Bmob
103 | {
104 |
105 | private MonoBehaviour go;
106 |
107 | ///
108 | /// Unity Behavior
109 | ///
110 | public void Update() { }
111 |
112 | public BmobUnity()
113 | {
114 | Configuration.PLATFORM = SDKTarget.Unity;
115 | go = this;
116 | }
117 |
118 | ///
119 | /// 仅用于在界面设置
120 | ///
121 | public String ApplicationId;
122 | public String RestKey;
123 |
124 | internal override string appKey
125 | {
126 | get
127 | {
128 | return ApplicationId;
129 | }
130 | set
131 | {
132 | ApplicationId = value;
133 | base.appKey = value;
134 | }
135 | }
136 | internal override String restKey
137 | {
138 | get { return RestKey; }
139 | set
140 | {
141 | RestKey = value;
142 | base.restKey = value;
143 | }
144 | }
145 |
146 |
147 | internal override void submit(BmobCommand command, BmobCallback callback)
148 | {
149 | this.go.StartCoroutine(execute(command, callback));
150 | }
151 |
152 | ///
153 | /// 调用
154 | ///
155 | private IEnumerator execute(BmobCommand command, BmobCallback callback)
156 | {
157 | return command.execute(Request, callback);
158 | }
159 |
160 | protected virtual IEnumerator Request(String url, String method, String contentType, byte[] postData, IDictionary headers, Action callback)
161 | {
162 | BmobOutput.Save(headers, "Content-Type", contentType);
163 |
164 | // http://answers.unity3d.com/questions/785798/put-with-wwwform.html
165 | // www不支持PUT和DELETE操作,需要服务端支持!!服务端已添加filter 2015年9月25日09:57:52
166 | BmobOutput.Save(headers, "X-HTTP-Method-Override", method);
167 |
168 | return RequestInternal(url, method, postData, headers, callback);
169 | }
170 |
171 | private IEnumerator RequestInternal(String url, String method, byte[] postData, IDictionary headers, Action callback)
172 | {
173 | var table = new Dictionary();
174 | foreach (var header in headers)
175 | {
176 | table.Add(header.Key, header.Value);
177 | }
178 | WWW www = new WWW(url, method.Equals("GET") ? null : postData, table);
179 |
180 | yield return www;
181 |
182 | var error = www.error;
183 | var text = www.text;
184 |
185 | BmobDebug.T("[ BmobUnity ] after fetch www message, Response: '" + text + "', Error: ' " + error + "'");
186 |
187 |
188 | var status = new Status(200, error);
189 |
190 | // if (www.responseHeaders.ContainsKey("STATUS"))
191 | // {
192 | // var respStatus = www.responseHeaders["STATUS"];
193 | // var statusCode = Regex.Replace(respStatus, @"[^ ]* (\d*) .*", "$1");
194 | // status.code = Convert.ToInt32(statusCode);
195 | // }
196 | try{
197 | if (www.responseHeaders.ContainsKey("STATUS"))
198 | {
199 | var respStatus = www.responseHeaders["STATUS"];
200 | var statusCode = Regex.Replace(respStatus, @"[^ ]* (\d*) .*", "$1");
201 | status.code = Convert.ToInt32(statusCode);
202 | }
203 | }catch(NullReferenceException e){
204 | BmobDebug.T("www.responseHeaders方法有问题: "+e);
205 | // Unity 2017.2.0f3 (64-bit) 版本,www.responseHeaders方法在真机上有问题。zq,2017.10.24
206 | if(error != null){
207 | foreach (Match match in Regex.Matches(error, @" *(\d*) *")){
208 | status.code = Convert.ToInt32(match.Value);
209 | break;
210 | }
211 | }
212 | }
213 |
214 |
215 | if (error != null && error != "")
216 | {
217 | // 返回了错误的内容,不表示返回的内容就为空!!
218 | callback(text, status, new BmobException(error));
219 | }
220 | else
221 | {
222 | callback(text, status, null);
223 | }
224 | }
225 |
226 | }
227 |
228 | }
229 |
230 | #endif
231 |
--------------------------------------------------------------------------------
/core/src/api/BmobWindows.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Threading;
4 | using cn.bmob.io;
5 | using cn.bmob.response;
6 | using System.Text;
7 | using System.Collections;
8 | using System.Net;
9 | using System.IO;
10 | using System.Diagnostics;
11 | using cn.bmob.http;
12 | using cn.bmob.Extensions;
13 | using cn.bmob.config;
14 | using cn.bmob.exception;
15 | using System.Text.RegularExpressions;
16 |
17 | namespace cn.bmob.api
18 | {
19 |
20 | #if FRAMEWORK || WINDOWS_PHONE
21 | public class BmobWindows : Bmob
22 | {
23 |
24 | public BmobWindows()
25 | {
26 | Configuration.PLATFORM = SDKTarget.WindowsDesktop;
27 | }
28 |
29 | internal override void submit(BmobCommand command, BmobCallback callback)
30 | {
31 | command.execute(Request, callback);
32 | }
33 |
34 | /* internal */
35 | public int Request(String url, String method, String contentType, byte[] postData, IDictionary headers, Action callback)
36 | {
37 | return requestInternal(url, method, contentType, postData, headers, callback);
38 | }
39 |
40 | private int requestInternal(String url, String method, string ContentType, byte[] postData, IDictionary headers, Action callback)
41 | {
42 | var http = new Http();
43 | http.Method = method;
44 | http.RequestContentType = ContentType;
45 | http.Headers = headers;
46 | http.RequestBodyBytes = postData;
47 | http.Url = new Uri(url);
48 |
49 | // http模块有包括了网络异常的处理
50 | http.ExecuteAsync((raw, _) =>
51 | {
52 | var status = new Status((int)raw.StatusCode, raw.StatusDescription);
53 | callback(raw.Content, status, raw.ErrorException != null ? new BmobException(raw.ErrorException) : null);
54 | });
55 |
56 | return 0;
57 | }
58 | }
59 | #endif
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/core/src/api/IBmobAPI.cs:
--------------------------------------------------------------------------------
1 | using cn.bmob.http;
2 | using cn.bmob.io;
3 | using cn.bmob.response;
4 | using System;
5 | using System.Collections.Generic;
6 |
7 | namespace cn.bmob.api
8 | {
9 | ///
10 | /// SDK对外API抽象接口类
11 | ///
12 | public interface IBmobAPI
13 | {
14 |
15 | void initialize(string appKey, String restKey);
16 | void resetDomain(string url);
17 |
18 | // /
19 |
20 | void Create(string tablename, IBmobWritable data, BmobCallback callback);
21 | void Update(string tablename, string objectId, IBmobWritable data, BmobCallback callback);
22 | void Delete(string tablename, string objectId, BmobCallback callback);
23 | void Get(string tablename, string objectId, BmobCallback callback);
24 | void Find(string tablename, BmobQuery query, BmobCallback> callback);
25 |
26 | // /
27 |
28 | void Signup(T user, BmobCallback callback) where T : BmobUser;
29 | void Login(string username, string pwd, BmobCallback callback) where T : BmobUser;
30 |
31 | void UpdateUser(string objectId, BmobUser data, string sessionToken, BmobCallback callback);
32 | void DeleteUser(string objectId, string sessionToken, BmobCallback callback);
33 |
34 | void Reset(string email, BmobCallback callback);
35 | void EmailVerify(string email, BmobCallback callback);
36 |
37 | // /
38 |
39 | void Batch(BmobBatch requests, BmobCallback>> callback);
40 | void Endpoint(string eMethod, IDictionary parameters, BmobCallback> callback);
41 |
42 | void FileUpload(BmobLocalFile file, BmobCallback callback);
43 | void FileDelete(String url, BmobCallback callback);
44 |
45 | void Thumbnail(ThumbnailParameter param, BmobCallback callback);
46 | void Push(PushParamter param, BmobCallback callback);
47 |
48 | void Timestamp(BmobCallback callback);
49 | void Sql(string bql, List