Пример #1
0
        private static void GetModelDataListFromCloudP(bool publicOnly, bool includeUsername, Action <List <ModelData> > successAction, Action <string> failedAction)
        {
            var serverDataQuery = new ParseQuery <ParseObject>("ServerData");

            if (publicOnly)
            {
                serverDataQuery = serverDataQuery.WhereEqualTo("is_private", false);
            }

            var query = new ParseQuery <ParseObject>("UserServers");

            query = query.WhereMatchesQuery("model", serverDataQuery);
            query = query.Include("model");
            query = query.Include("user");

            query = query.OrderByDescending("updateAt");

            query.FindAsync().ContinueWith(t => {
                if (t.IsFaulted || t.IsCanceled)
                {
                    if (failedAction != null)
                    {
                        failedAction(t.Exception.Message);
                    }
                }
                else
                {
                    if (successAction != null)
                    {
                        IEnumerable <ParseObject> parseDatas = t.Result;
                        var results = new List <ModelData>();

                        foreach (var parseData in parseDatas)
                        {
                            var data = new ModelData();

                            var parseModelData = parseData.Get <ParseObject>("model");
                            var parseUserData  = parseData.Get <ParseUser>("user");

                            data.objectId  = parseModelData.ObjectId;
                            data.username  = parseUserData.Username;
                            data.modelFile = parseModelData.Get <ParseFile>("model_file").Name;
                            data.modelUrl  = parseModelData.Get <ParseFile>("model_file").Url.AbsoluteUri;


                            data.name          = parseModelData.Get <string>("name");
                            data.isPrivate     = parseModelData.Get <bool>("is_private");
                            data.unitSize      = parseModelData.Get <int>("unit_size");
                            data.cpuCoresCount = parseModelData.Get <int>("cpu_count");
                            data.cpuHz         = parseModelData.Get <int>("cpu_hz");
                            data.hddBaysCount  = parseModelData.Get <int>("hdd_count");
                            data.memorySpeed   = parseModelData.Get <int>("memory_speed");

                            data.memoryCapacity = PairData.FromListOfIntsToList(parseModelData.Get <IList <int> >("memory_capacity"));

                            data.raid = parseModelData.Get <string>("raid");

                            data.hdd = PairData.FromListOfIntsToList(parseModelData.Get <IList <int> >("hdd"));
                            var gpus = (parseModelData.Get <IList <string> >("gpu"));
                            data.gpu = new List <string>();
                            foreach (var gpu in gpus)
                            {
                                data.gpu.Add(gpu);
                            }

                            results.Add(data);
                        }

                        successAction(results);
                    }
                }
            });
        }
Пример #2
0
        private static void SaveInCloudLC(ModelData data, Action successAction, Action <string> failedAction)
        {
            AVObject avData = new AVObject("ServerData");

            bool isNewModel = true;

            if (data.objectId != null && !data.objectId.Equals(""))
            {
                avData.ObjectId = data.objectId;
                isNewModel      = false;
            }

            avData["name"]            = data.name;
            avData["is_private"]      = data.isPrivate;
            avData["unit_size"]       = data.unitSize;
            avData["cpu_count"]       = data.cpuCoresCount;
            avData["cpu_hz"]          = data.cpuHz;
            avData["hdd_count"]       = data.hddBaysCount;
            avData["memory_speed"]    = data.memorySpeed;
            avData["memory_capacity"] = PairData.ToArrayOfInts(data.memoryCapacity);
            avData["raid"]            = data.raid;
            avData["hdd"]             = PairData.ToArrayOfInts(data.hdd);
            avData["network"]         = PairData.ToArrayOfInts(data.network);
            avData["gpu"]             = data.gpu;

            avData.SaveAsync().ContinueWith(t => {
                if (t.IsFaulted || t.IsCanceled)
                {
                    if (failedAction != null)
                    {
                        var dataString = "";
                        foreach (var key in t.Exception.Data.Keys)
                        {
                            dataString += t.Exception.Data[key] + "\n";
                        }
                        failedAction(t.Exception.Message + "\n" + dataString);
                    }
                }
                else
                {
                    if (isNewModel)
                    {
                        var userToServers      = new AVObject("UserServers");
                        userToServers["user"]  = AVUser.CurrentUser;
                        userToServers["model"] = avData;

                        userToServers.SaveAsync().ContinueWith(t2 => {
                            if (t2.IsFaulted || t2.IsCanceled)
                            {
                                Debug.Log("User To Servers Failed");
                                if (failedAction != null)
                                {
                                    failedAction(t.Exception.Message);
                                }
                            }
                            else
                            {
                                if (successAction != null)
                                {
                                    successAction();
                                }
                            }
                        });
                    }
                    else
                    {
                        if (successAction != null)
                        {
                            successAction();
                        }
                    }
                }
            });
        }
Пример #3
0
        private static void SaveInCloudP(ModelData data, Action successAction, Action <string> failedAction)
        {
            ParseObject parseData = new ParseObject("ServerData");

            bool isNewModel = true;

            if (data.objectId != null && !data.objectId.Equals(""))
            {
                parseData.ObjectId = data.objectId;
                isNewModel         = false;
            }

            parseData["name"]            = data.name;
            parseData["is_private"]      = data.isPrivate;
            parseData["unit_size"]       = data.unitSize;
            parseData["cpu_count"]       = data.cpuCoresCount;
            parseData["cpu_hz"]          = data.cpuHz;
            parseData["hdd_count"]       = data.hddBaysCount;
            parseData["memory_speed"]    = data.memorySpeed;
            parseData["memory_capacity"] = PairData.ToArrayOfInts(data.memoryCapacity);
            parseData["raid"]            = data.raid;
            parseData["hdd"]             = PairData.ToArrayOfInts(data.hdd);
            parseData["network"]         = PairData.ToArrayOfInts(data.network);
            parseData["gpu"]             = data.gpu;

            parseData.SaveAsync().ContinueWith(t => {                   // 1. Save basic data
                if (t.IsFaulted || t.IsCanceled)
                {
                    if (failedAction != null)
                    {
                        var dataString = "";
                        foreach (var key in t.Exception.Data.Keys)
                        {
                            dataString += t.Exception.Data[key] + "\n";
                        }
                        failedAction(t.Exception.Message + "\n" + dataString);
                    }
                }
                else
                {
                    if (isNewModel)
                    {
                        var userToServers      = new ParseObject("UserServers");
                        userToServers["user"]  = ParseUser.CurrentUser;
                        userToServers["model"] = parseData;

                        userToServers.SaveAsync().ContinueWith(t2 => {                          // 2. Save user information
                            if (t2.IsFaulted || t2.IsCanceled)
                            {
                                Debug.Log("User To Servers Failed");
                                if (failedAction != null)
                                {
                                    failedAction(t2.Exception.Message);
                                }
                            }
                            else
                            {
                                var parts = data.modelPath.Split('.');
                                var file  = new ParseFile("model." + parts[parts.Length - 1], File.ReadAllBytes(data.modelPath));
                                parseData["model_file"] = file;
                                parseData.SaveAsync().ContinueWith(t3 => {                                      // 3. save model file
                                    if (t3.IsFaulted || t3.IsCanceled)
                                    {
                                        Debug.Log("User To Servers Failed");
                                        if (failedAction != null)
                                        {
                                            failedAction(t3.Exception.Message);
                                        }
                                    }
                                    else
                                    {
                                        if (successAction != null)
                                        {
                                            successAction();
                                        }
                                    }
                                });
                            }
                        });
                    }
                    else
                    {
                        if (successAction != null)
                        {
                            successAction();
                        }
                    }
                }
            });
        }