Exemplo n.º 1
0
    protected override void OnButtonClick(Button btn)
    {
        base.OnButtonClick(btn);
        switch (btn.name)
        {
        case "Rank2StartFrameBtn":
        case "RankData2StartFrameBtn":
            GuiController.Instance.SwitchWrapperWithScale(GuiFrameID.StartFrame, false);
            break;

        case "RankDataBtn":
            if (isDownloading)
            {
                return;
            }
            isDownloading = true;
            curInstance   = new CategoryInstance(curPatternID, curAmountID, curSymbolID, curDigitID, curOperandID);
            GameManager.Instance.DownloadRecord(curInstance, OnDownloadSucceed, OnDownloadFail);
            break;

        case "RankData2RankFrameBtn":
            CommonTool.GuiHorizontalMove(rankDataContent, Screen.width, MoveID.RightOrUp, canvasGroup, false);
            break;

        default:
            MyDebug.LogYellow("Can not find Button: " + btn.name);
            break;
        }
    }
Exemplo n.º 2
0
    protected override void OnButtonClick(Button btn)
    {
        base.OnButtonClick(btn);
        switch (btn.name)
        {
        case "Category2StartFrameBtn":
            GuiController.Instance.SwitchWrapperWithScale(GuiFrameID.StartFrame, false);
            break;

        case "Category2FightFrameBtn":
            CategoryInstance curCategoryInstance = new CategoryInstance(curPatternID, curAmountID, curSymbolID, curDigitID, curOperandID);
            GuiController.Instance.CompetitionGUI        = GuiFrameID.CategoryFrame;
            FightController.Instance.CurCategoryInstance = curCategoryInstance;
            GuiController.Instance.SwitchWrapper(GuiFrameID.FightFrame);
            break;

        //case "CategoryTipBtn":
        //case "CategoryTipBg":
        //case "CategoryTipPage":
        //    categoryTipBg.SetActive(!categoryTipBg.activeSelf);
        //    break;
        default:
            MyDebug.LogYellow("Can not find Button: " + btn.name);
            break;
        }
    }
Exemplo n.º 3
0
        public async Task TestAddUpdateRemoveCategoryInstance()
        {
            var templates = Controller.GetTemplates().ToList();
            var instances = Controller.GetInstances().ToList();

            var template    = templates.First();
            var newInstance = new CategoryInstance
            {
                ObjId = Guid.NewGuid(),
                Name  = "TestCategory",
                This2CategoryGroup = template.ObjId,
                Color      = "green",
                IsFavorite = true,
                Rating     = 5,
                Icon       = "test-icon"
            };

            instances.Add(newInstance);

            // add instance
            var saved = (await Controller.SaveInstances(instances)).ToList();

            var savedInstance = saved.FirstOrDefault(a => a.ObjId == newInstance.ObjId);

            Assert.NotNull(savedInstance);
            Assert.Equal(newInstance.Name, savedInstance.Name);
            Assert.Equal(newInstance.This2CategoryGroup, savedInstance.This2CategoryGroup);
            Assert.Equal(newInstance.Color, savedInstance.Color);
            Assert.Equal(newInstance.IsFavorite, savedInstance.IsFavorite);
            Assert.Equal(newInstance.Rating, savedInstance.Rating);
            Assert.Equal(newInstance.Icon, savedInstance.Icon);


            // update instance
            savedInstance.Name = "update name...";
            saved = (await Controller.SaveInstances(saved)).ToList();

            var updatedInstance = saved.FirstOrDefault(a => a.ObjId == newInstance.ObjId);

            Assert.NotNull(updatedInstance);
            Assert.Equal(savedInstance.Name, updatedInstance.Name);
            Assert.Equal(savedInstance.This2CategoryGroup, updatedInstance.This2CategoryGroup);
            Assert.Equal(savedInstance.Color, updatedInstance.Color);
            Assert.Equal(savedInstance.IsFavorite, updatedInstance.IsFavorite);
            Assert.Equal(savedInstance.Rating, updatedInstance.Rating);
            Assert.Equal(savedInstance.Icon, updatedInstance.Icon);


            //remove instance
            instances.Remove(newInstance);
            saved = (await Controller.SaveInstances(instances)).ToList();

            Assert.Null(saved.FirstOrDefault(a => a.ObjId == newInstance.ObjId));
        }
Exemplo n.º 4
0
    private CategoryInstance ConvertToCategory(Category category)
    {
        CategoryInstance instance = new CategoryInstance();

        instance.patternID = (PatternID)(category.model - 1);
        instance.amountID  = (AmountID)(category.num - 1);
        instance.symbolID  = (SymbolID)(category.calcu - 1);
        instance.digitID   = (DigitID)(category.digit - 2);
        instance.operandID = (OperandID)(category.operate - 2);
        return(instance);
    }
Exemplo n.º 5
0
    public static void ExchangeAchievement()
    {
        string       addressList       = Application.dataPath + "/Achievement.txt";
        string       targetList        = Application.dataPath + "/Resources/Achievement/Achievement.txt";
        StreamReader mutiLanguageAsset = new StreamReader(addressList);

        if (mutiLanguageAsset == null)
        {
            MyDebug.LogYellow("Can not find: " + addressList);
            return;
        }
        char[] charSeparators = new char[] { "\r"[0], "\n"[0] };
        string asset          = mutiLanguageAsset.ReadToEnd();

        string[] lineArray = asset.Split(charSeparators, System.StringSplitOptions.RemoveEmptyEntries);
        string[] lineList;
        List <AchievementInstance> achList = new List <AchievementInstance>();

        for (int j = 1; j < lineArray.Length; j++)
        {
            AchievementInstance instance = new AchievementInstance();
            lineList = lineArray[j].Split(',');
            instance.achievementName = lineList[0];
            float.TryParse(lineList[1], out instance.accuracy);
            float.TryParse(lineList[2], out instance.meanTime);
            instance.mainTitleIndex    = lineList[3];
            instance.subTitleIndex     = lineList[4];
            instance.imageIndex        = lineList[5];
            instance.chapterImageIndex = lineList[6];
            int patternID = 0;
            int amountID  = 0;
            int symbolID  = 0;
            int digitID   = 0;
            int operandID = 0;
            int.TryParse(lineList[7], out patternID);
            int.TryParse(lineList[8], out amountID);
            int.TryParse(lineList[9], out symbolID);
            int.TryParse(lineList[10], out digitID);
            int.TryParse(lineList[11], out operandID);
            CategoryInstance cInstance = new CategoryInstance(patternID, amountID, symbolID, digitID, operandID);
            instance.cInstance = cInstance;
            int.TryParse(lineList[12], out instance.difficulty);
            instance.finishTime = "";
            instance.star       = 0;
            achList.Add(instance);
        }
        if (File.Exists(targetList))
        {
            File.Delete(targetList);
        }
        string toSave = JsonHelper.ToListJson <AchievementInstance>(achList);

        CommonTool.SetData(targetList, toSave);
    }
Exemplo n.º 6
0
    private bool CanRefreshRankData(CategoryInstance instance)
    {
        DateTime lastTime;
        bool     hasLastTime = lastRefreshTimeDict.TryGetValue(instance, out lastTime);

        if (hasLastTime)
        {
            TimeSpan ts = DateTime.Now - lastTime;
            return(ts.TotalSeconds > RefreshInterval);
        }

        return(true);
    }
        /// <summary>
        /// When a category mode selection is changed.
        /// </summary>
        /// <param name="category"></param>
        /// <param name="selected"></param>
        private void OnCategorySelectionToggle(CategoryInstance category, bool selected)
        {
            _isTogglingCategory = true;

            for (var i = 0; i < category.Options.Count; i++)
            {
                category.Options[i].IsSelected = selected;
            }

            _isTogglingCategory = false;

            CommitPinnedOptions();
        }
Exemplo n.º 8
0
    private void OnEnrollSucceed(CategoryInstance instance)
    {
        isEnrolling = false;
        RankController.Instance.AlreadyEnroll = true;
        activityEnrollBtn.gameObject.SetActive(false);
        activityRankDetailBtn.gameObject.SetActive(true);
        activityEnrollBoard.SetActive(false);
        RankController.Instance.ActivityCategory = instance;
        OpenRankDetailBoard();

        string message = LanguageController.Instance.GetLanguage("Text_20080");

        GuiController.Instance.CurCommonTipInstance = new CommonTipInstance(CommonTipID.Splash, message);
        GuiController.Instance.SwitchWrapper(GuiFrameID.CommonTipFrame, true);
    }
Exemplo n.º 9
0
    private void OpenRankDetailBoard()
    {
        activityRankDetailBoardBg.gameObject.SetActive(true);
        CategoryInstance instance = RankController.Instance.ActivityCategory;

        activityRankDetailPattern_Time.SetActive(instance.patternID == PatternID.Time);
        activityRankDetailPattern_Number.SetActive(instance.patternID == PatternID.Number);
        activityRankDetailTime.gameObject.SetActive(instance.patternID == PatternID.Time);
        activityRankDetailAmount.gameObject.SetActive(instance.patternID == PatternID.Number);
        activityRankDetailTime.text    = string.Format(activityRankDetailTime.text, FightController.Instance.GetTimeAmount(instance.amountID));
        activityRankDetailAmount.text  = string.Format(activityRankDetailAmount.text, FightController.Instance.GetNumberAmount(instance.amountID));
        activityRankDetailSymbol.text  = string.Format(activityRankDetailSymbol.text, FightController.Instance.GetSymbol(instance.symbolID));
        activityRankDetailDigit.text   = string.Format(activityRankDetailDigit.text, (int)(instance.digitID + 2));
        activityRankDetailOperand.text = string.Format(activityRankDetailOperand.text, (int)(instance.operandID + 2));
    }
Exemplo n.º 10
0
        public async Task TestInvalidSave()
        {
            var instances = Controller.GetInstances().ToList();

            var newInstance = new CategoryInstance
            {
                ObjId      = Guid.NewGuid(),
                Name       = "TestCategory",
                Color      = "green",
                IsFavorite = true,
                Rating     = 5,
                Icon       = "test-icon"
            };

            instances.Add(newInstance);

            // add instance
            await Assert.ThrowsAsync <DbUpdateException>(async() => await Controller.SaveInstances(instances));
        }
Exemplo n.º 11
0
        public MessageControl(MessageInstance message)
        {
            InitializeComponent();

            this.Message = message;
            user = new MediaAccount() {ID = message.MediaAccount};
            category = new CategoryInstance() {ID = message.Category};

            if (Message.Media != null)
            {
                Media media = new Media() {ID = Message.Media.Value};
                media = DatabaseManager.ContainsItem(media, new [] {"ID"});
                picMedia.ImageLocation = media.Url;
                hasMedia = true;
            }
            else
            {
                flowLayoutPanel1.Controls.Remove(panelMedia);
                Controls.Remove(flowLayoutPanel1);
            }
            user = DatabaseManager.ContainsItem(user, new[] {"ID"});
            category = DatabaseManager.ContainsItem(category, new[] {"ID"});
            Likes =
                int.Parse(
                    DatabaseManager.QueryFirst("SELECT COUNT(*) FROM Likes WHERE message=" + message.ID)["Column1"]
                        .ToString());
            DidLike =
                DatabaseManager.ContainsItem(new Likes() {Message = message.ID, MediaAccount = Globals.Account.ID},
                    new[] {"Message", "MediaAccount"}) !=
                null;

            picUser.ImageLocation = user.Picture;
            lblUsername.Text = user.Username;
            lblDate.Text = message.Datum.ToShortDateString();
            lblMessage.Text = message.Report;

            lblTitle.Text = string.IsNullOrEmpty(message.Title) ? category.Name : $"{message.Title} - {category.Name}";
            IsWriting = false;
            if (Globals.Account.ID != message.MediaAccount)
                Controls.Remove(lblRemove);
        }
Exemplo n.º 12
0
        protected void CreateCategory(string title, List <OptionDefinition> options)
        {
            options.Sort((d1, d2) => d1.SortPriority.CompareTo(d2.SortPriority));

            var groupInstance    = SRInstantiate.Instantiate(CategoryGroupPrefab);
            var categoryInstance = new CategoryInstance(groupInstance);

            _categories.Add(categoryInstance);

            groupInstance.CachedTransform.SetParent(ContentContainer, false);
            groupInstance.Header.text          = title;
            groupInstance.SelectionModeEnabled = false;

            categoryInstance.CategoryGroup.SelectionToggle.onValueChanged.AddListener(
                b => OnCategorySelectionToggle(categoryInstance, b));

            foreach (var option in options)
            {
                var control = OptionControlFactory.CreateControl(option, title);

                if (control == null)
                {
                    Debug.LogError("[SRDebugger.OptionsTab] Failed to create option control for {0}".Fmt(option.Name));
                    continue;
                }

                categoryInstance.Options.Add(control);
                control.CachedTransform.SetParent(groupInstance.Container, false);
                control.IsSelected           = Service.PinnedUI.HasPinned(option);
                control.SelectionModeEnabled = false;
                control.SelectionModeToggle.onValueChanged.AddListener(OnOptionSelectionToggle);

                _options.Add(option, control);
                _controls.Add(control);
            }
        }
Exemplo n.º 13
0
        public static void EnusreDatabaseCreated(IServiceProvider services)
        {
            var context         = services.GetRequiredService <AutomaticaContext>();
            var visuInitFactory = services.GetRequiredService <IVisualisationFactory>();
            var config          = services.GetRequiredService <IConfiguration>();

            context.Database.Migrate();

            bool dbCreated = !context.BoardTypes.Any();



            if (dbCreated)
            {
                context.Database.ExecuteSqlCommand($@"	       

		            INSERT INTO RuleInterfaceDirections (ObjId, Name, Description, Key) VALUES 
		                (1, 'Input', 'Input', 'I'),
		                (2, 'Output', 'Output', 'O'),
		                (3, 'Parameter', 'Parameter', 'P');

	                INSERT INTO Settings (ObjId, ValueKey, ValueInt, Type) VALUES (1, 'ConfigVersion', 0, 0);

		        
		        INSERT INTO RulePageTypes (ObjId, Name, Description, Key) VALUES 
		        (1, 'Rules', 'Rules', 'rules');


		        INSERT INTO VisuPageTypes (ObjId, Name, Description, Key) VALUES 
		        (1, 'PC', 'PC', 'pc');


		        INSERT INTO VisuPageTypes (ObjId, Name, Description, Key) VALUES 
		        (2, 'Mobile', 'Mobile', 'mobile')"        );
                context.SaveChanges();
            }

            var lat = context.Settings.SingleOrDefault(a => a.ValueKey == "Latitude");

            if (lat == null)
            {
                context.Settings.Add(new Setting
                {
                    ValueKey  = "Latitude",
                    Type      = (long)PropertyTemplateType.Numeric,
                    Value     = 0,
                    Group     = "SERVER.SETTINGS",
                    IsVisible = true,
                    Order     = 10
                });

                context.Settings.Add(new Setting
                {
                    ValueKey  = "Longitude",
                    Type      = (long)PropertyTemplateType.Numeric,
                    Value     = 0,
                    Group     = "SERVER.SETTINGS",
                    IsVisible = true,
                    Order     = 11
                });
            }
            else
            {
                var longi = context.Settings.SingleOrDefault(a => a.ValueKey == "Longitude");

                if (lat.ValueDouble == null)
                {
                    lat.ValueDouble = 0;
                }

                if (longi.ValueDouble == null)
                {
                    longi.ValueDouble = 0;
                }

                context.Settings.Update(longi);
                context.Settings.Update(lat);
            }

            var apiKey = context.Settings.SingleOrDefault(a => a.ValueKey == "apiKey");

            if (apiKey == null)
            {
                context.Settings.Add(new Setting
                {
                    ValueKey  = "apiKey",
                    Type      = (long)PropertyTemplateType.Text,
                    Value     = "",
                    Group     = "SERVER.SETTINGS",
                    IsVisible = true,
                    Order     = 0
                });
            }

            var autoUpdate      = context.Settings.SingleOrDefault(a => a.ValueKey == "autoUpdate");
            var autoUpdateTime  = context.Settings.SingleOrDefault(a => a.ValueKey == "autoUpdateTime");
            var reportCrashLogs = context.Settings.SingleOrDefault(a => a.ValueKey == "reportCrashLogs");

            if (autoUpdate == null)
            {
                context.Settings.Add(new Setting
                {
                    ValueKey  = "autoUpdate",
                    Type      = (long)PropertyTemplateType.Bool,
                    Value     = false,
                    Group     = "SERVER.SETTINGS",
                    IsVisible = true,
                    Order     = 20
                });
            }
            else
            {
                autoUpdate.Order = 20;
                context.Update(autoUpdate);
            }

            if (autoUpdateTime == null)
            {
                context.Settings.Add(new Setting
                {
                    ValueKey  = "autoUpdateTime",
                    Type      = (long)PropertyTemplateType.Time,
                    Value     = new DateTime(2000, 12, 31, 2, 0, 0),
                    Group     = "SERVER.SETTINGS",
                    IsVisible = true,
                    Order     = 21
                });
            }
            else
            {
                autoUpdateTime.Order = 21;
                autoUpdateTime.Type  = (long)PropertyTemplateType.Time;
                context.Update(autoUpdateTime);
            }

            if (reportCrashLogs == null)
            {
                context.Settings.Add(new Setting
                {
                    ValueKey  = "reportCrashLogs",
                    Type      = (long)PropertyTemplateType.Bool,
                    Value     = false,
                    Group     = "SERVER.SETTINGS",
                    IsVisible = true,
                    Order     = 22
                });
            }
            else
            {
                reportCrashLogs.Order = 22;
                context.Update(reportCrashLogs);
            }

            var cloudUrl = context.Settings.SingleOrDefault(a => a.ValueKey == "cloudUrl");

            if (cloudUrl == null)
            {
                context.Settings.Add(new Setting
                {
                    ValueKey  = "cloudUrl",
                    Type      = (long)PropertyTemplateType.Text,
                    Value     = "https://automatica-core-cloud.azurewebsites.net",
                    Group     = "SERVER.SETTINGS",
                    IsVisible = true,
                    Order     = 1
                });
            }

            var propertyTypes = Enum.GetValues(typeof(PropertyTemplateType));

            foreach (var propertyType in propertyTypes)
            {
                var propertyTypeDb = context.PropertyTypes.SingleOrDefault(a => a.Type == (int)propertyType);
                var isNewObject    = false;
                if (propertyTypeDb == null)
                {
                    propertyTypeDb = new PropertyType {
                        Type = (int)propertyType
                    };
                    isNewObject = true;
                }

                var type       = propertyType.GetType();
                var memInfo    = type.GetMember(propertyType.ToString());
                var attributes = memInfo[0].GetCustomAttributes(typeof(PropertyTemplateTypeAttribute), false);

                if (attributes.Length > 0 && attributes[0] is PropertyTemplateTypeAttribute attribute)
                {
                    propertyTypeDb.Name        = attribute.Name;
                    propertyTypeDb.Description = attribute.Description;
                    propertyTypeDb.Meta        = attribute.Meta;
                }
                else
                {
                    propertyTypeDb.Name        = propertyType.GetType().Name;
                    propertyTypeDb.Description = propertyType.GetType().Name;
                    propertyTypeDb.Meta        = null;
                }

                if (isNewObject)
                {
                    context.PropertyTypes.Add(propertyTypeDb);
                }
                else
                {
                    context.PropertyTypes.Update(propertyTypeDb);
                }
            }

            var nodeDataTypes = Enum.GetValues(typeof(NodeDataType));

            foreach (var nodeDataType in nodeDataTypes)
            {
                var nodeDataTypeDb = context.NodeDataTypes.SingleOrDefault(a => a.Type == (int)nodeDataType);
                var isNewObject    = false;
                if (nodeDataTypeDb == null)
                {
                    nodeDataTypeDb      = new EF.Models.NodeDataType();
                    nodeDataTypeDb.Type = (int)nodeDataType;
                    isNewObject         = true;
                }

                var type       = nodeDataType.GetType();
                var memInfo    = type.GetMember(nodeDataType.ToString());
                var attributes = memInfo[0].GetCustomAttributes(typeof(NodeDataTypeEnumAttribute), false);

                if (attributes.Length > 0 && attributes[0] is NodeDataTypeEnumAttribute attribute)
                {
                    nodeDataTypeDb.Name        = attribute.Name;
                    nodeDataTypeDb.Description = attribute.Description;
                }
                else
                {
                    nodeDataTypeDb.Name        = nodeDataType.GetType().Name;
                    nodeDataTypeDb.Description = nodeDataType.GetType().Name;
                }

                if (isNewObject)
                {
                    context.NodeDataTypes.Add(nodeDataTypeDb);
                }
                else
                {
                    context.NodeDataTypes.Update(nodeDataTypeDb);
                }
            }


            context.SaveChanges();
            visuInitFactory.Initialize(context, config);
            context.SaveChanges();

            CreateInterfaceTypes(context);
            AddSystemTemplates(context);
            AddRaspberryPi3Board(context);
            AddAreaData(context);
            CategoryGroup.GenerateDefault(context);
            context.SaveChanges();
            CategoryInstance.GenerateDefault(context);

            context.SaveChanges();


            if (!context.AreaInstances.Any())
            {
                var projectInstance = new AreaInstance
                {
                    ObjId             = Guid.NewGuid(),
                    Name              = "Project",
                    Description       = "",
                    Icon              = "home",
                    This2AreaTemplate = AreaTemplateAttribute.GetFromEnum(AreaTemplates.Project),
                    This2Parent       = null
                };
                context.AreaInstances.Add(projectInstance);
            }

            if (dbCreated)
            {
                var rootNodeTemplate = context.NodeTemplates.SingleOrDefault(a => a.ObjId == GuidTemplateTypeAttribute.GetFromEnum(BoardTypeEnum.RaspberryPi3));
                var rootNode         = NodeInstanceFactory.CreateNodeInstanceFromTemplate(rootNodeTemplate);

                rootNode.Name        = "Raspberry PI 3";
                rootNode.Description = "";

                context.NodeInstances.Add(rootNode);

                var childs = context.NodeTemplates.Where(a => a.NeedsInterface2InterfacesType == rootNodeTemplate.ObjId);

                foreach (var child in childs)
                {
                    if (child.NeedsInterface2InterfacesType == child.ProvidesInterface2InterfaceType)
                    {
                        continue;
                    }
                    var node = NodeInstanceFactory.CreateNodeInstanceFromTemplate(child);
                    node.This2ParentNodeInstance = rootNode.ObjId;
                    context.NodeInstances.Add(node);
                }


                var rulePage = new RulePage
                {
                    ObjId             = Guid.NewGuid(),
                    Name              = "Page1",
                    Description       = "",
                    This2RulePageType = 1
                };

                context.RulePages.Add(rulePage);


                var visuPage = new VisuPage
                {
                    ObjId             = Guid.NewGuid(),
                    Name              = "Page1",
                    Description       = "",
                    This2VisuPageType = 2,
                    DefaultPage       = true
                };

                context.VisuPages.Add(visuPage);

                AddInitUserManagementData(context);

                context.SaveChanges();
            }


            context.SaveChanges();
        }
Exemplo n.º 14
0
    /// <summary>
    /// 拉取排行榜信息
    /// </summary>
    /// <param name="form"></param>
    /// <param name="OnSucceed"></param>
    /// <returns></returns>
    public IEnumerator DownloadRecord(CategoryInstance instance, Action <ArrayList> OnSucceed, Action <string> OnFail)
    {
        if (!CanRefreshRankData(instance))
        {
            List <RankInstance> instances;
            rankDataDict.TryGetValue(instance, out instances);
            if (instances != null && instances.Count > 0)
            {
                if (OnSucceed != null)
                {
                    ArrayList dataList = new ArrayList(instances);
                    OnSucceed(dataList);
                }
            }
            else
            {
                if (OnFail != null)
                {
                    string msg = LanguageController.Instance.GetLanguage("Text_20071");
                    OnFail(msg);
                }
            }
            yield break;
        }

        WWWForm form = new WWWForm();

        form.AddField("userId", GameManager.Instance.UserID);
        form.AddField("jwttoken", GameManager.Instance.Token);
        form.AddField("model", (int)instance.patternID + 1);
        form.AddField("num", (int)instance.amountID + 1);
        form.AddField("calcu", (int)instance.symbolID + 1);
        form.AddField("digit", (int)instance.digitID + 2);
        form.AddField("operate", (int)instance.operandID + 2);

        WWW www = new WWW(DownloadURL, form);

        float responseTime = 0;

        while (!www.isDone && responseTime < TimeOut)
        {
            responseTime += Time.deltaTime;
            yield return(www);
        }

        string message = "";

        if (www.isDone)
        {
            DownloadDataResponse response = JsonUtility.FromJson <DownloadDataResponse>(www.text);
            if (response != null)
            {
                if (response.code == (int)CodeID.SUCCESS)
                {
                    MyDebug.LogGreen("Download Rank Data Succeed!");
                    lastRefreshTimeDict[instance] = DateTime.Now;
                    if (response.data != null && response.data.Count > 0)
                    {
                        rankDataDict[instance] = response.data;
                        if (OnSucceed != null)
                        {
                            ArrayList dataList = new ArrayList(response.data);
                            OnSucceed(dataList);
                        }
                        yield break;
                    }
                    else
                    {
                        message = LanguageController.Instance.GetLanguage("Text_20071");
                    }
                }
                else if (response.code == (int)CodeID.GAME_VERSION_ERROR)
                {
                    MyDebug.LogYellow("Download Rank Data Fail:" + response.code);
                    message = LanguageController.Instance.GetLanguage("Text_20079");
                }
                else
                {
                    MyDebug.LogYellow("Download Rank Data Fail:" + response.code);
                    message = LanguageController.Instance.GetLanguage("Text_20066");
                }
            }
            else
            {
                MyDebug.LogYellow("Download Rank Data Fail: Message Is Not Response!");
                message = LanguageController.Instance.GetLanguage("Text_20066");
            }
        }
        else
        {
            MyDebug.LogYellow("Download Rank Data Fail: Long Time!");
            message = LanguageController.Instance.GetLanguage("Text_20067");
        }

        if (OnFail != null)
        {
            OnFail(message);
        }
    }
Exemplo n.º 15
0
        public void Reload()
        {
            user = new MediaAccount() {ID = Message.MediaAccount};
            category = new CategoryInstance() {ID = Message.Category};

            user = DatabaseManager.ContainsItem(user, new[] {"ID"});
            category = DatabaseManager.ContainsItem(category, new[] {"ID"});

            picUser.ImageLocation = user.Picture;
            lblUsername.Text = user.Username;
            lblDate.Text = Message.Datum.ToShortDateString();
            lblMessage.Text = Message.Report;

            lblTitle.Text = string.IsNullOrEmpty(Message.Title) ? category.Name : $"{Message.Title} - {category.Name}";
            IsWriting = false;
            if (Globals.Account.ID != Message.MediaAccount)
                Controls.Remove(lblRemove);
        }
Exemplo n.º 16
0
    /// <summary>
    /// 活动报名
    /// </summary>
    /// <param name="form"></param>
    /// <param name="OnSuccees"></param>
    /// <param name="OnFail"></param>
    /// <returns></returns>
    public IEnumerator EnrollActivity(WWWForm form, Action <CategoryInstance> OnSuccees, Action <string> OnFail)
    {
        WWW www = new WWW(EnrollURL, form);

        float responseTime = 0;

        while (!www.isDone && responseTime < TimeOut)
        {
            responseTime += Time.deltaTime;
            yield return(www);
        }

        string message = "";

        if (www.isDone)
        {
            EnrollActivityResponse response = JsonUtility.FromJson <EnrollActivityResponse>(www.text);
            if (response != null)
            {
                if (response.code == (int)CodeID.SUCCESS)
                {
                    MyDebug.LogGreen("Enroll Activity Succeed!");

                    if (OnSuccees != null)
                    {
                        CategoryInstance instance = ConvertToCategory(response.data);
                        OnSuccees(instance);
                    }
                    yield break;
                }
                else if (response.code == (int)CodeID.JOIN_TIME_ERROR)
                {
                    MyDebug.LogYellow("Enroll Activity Fail:" + response.code);
                    message = LanguageController.Instance.GetLanguage("Text_20081");
                }
                else if (response.code == (int)CodeID.GAME_VERSION_ERROR)
                {
                    MyDebug.LogYellow("Enroll Activity Fail:" + response.code);
                    message = LanguageController.Instance.GetLanguage("Text_20079");
                }
                else
                {
                    MyDebug.LogYellow("Enroll Activity Fail:" + response.code);
                    message = LanguageController.Instance.GetLanguage("Text_20066");
                }
            }
            else
            {
                MyDebug.LogYellow("Enroll Activity Fail: Message Is Not Response!");
                message = LanguageController.Instance.GetLanguage("Text_20066");
            }
        }
        else
        {
            MyDebug.LogYellow("Enroll Activity Fail: Long Time!");
            message = LanguageController.Instance.GetLanguage("Text_20067");
        }

        if (OnFail != null)
        {
            OnFail(message);
        }
    }
Exemplo n.º 17
0
    private void StartScan()
    {
        if (scaning)
        {
            MyDebug.LogYellow("Scaning!!!");
            return;
        }
        scaning = true;

        BluetoothLEHardwareInterface.RemoveCharacteristics();
        BluetoothLEHardwareInterface.RemoveServices();

        CategoryInstance curCategoryInstance = new CategoryInstance(curPatternID, curAmountID, curSymbolID, curDigitID, curOperandID);

        FightController.Instance.CurCategoryInstance = curCategoryInstance;

        string serviceUUID = (int)curAmountID + "" + (int)curSymbolID + "" + (int)curDigitID + "0";
        string readUUID    = (int)curAmountID + "" + (int)curSymbolID + "" + (int)curDigitID + "1";
        string writeUUID   = (int)curAmountID + "" + (int)curSymbolID + "" + (int)curDigitID + "2";

        BluetoothController.Instance.ServiceUUID = BluetoothLEHardwareInterface.FullUUID(serviceUUID);
        BluetoothController.Instance.ReadUUID    = BluetoothLEHardwareInterface.FullUUID(readUUID);
        BluetoothController.Instance.WriteUUID   = BluetoothLEHardwareInterface.FullUUID(writeUUID);

        MyDebug.LogGreen("ServiceUUID:" + BluetoothController.Instance.ServiceUUID);
        MyDebug.LogGreen("ReadUUID:" + BluetoothController.Instance.ReadUUID);
        MyDebug.LogGreen("WriteUUID:" + BluetoothController.Instance.WriteUUID);

        if (isCentral)
        {
            MyDebug.LogGreen("Central Start Scaning!");
            bluetoothScanResultContent.SetActive(true);
            RefreshScanResultContent();
            CommonTool.GuiHorizontalMove(bluetoothScanResultContent, Screen.width, MoveID.RightOrUp, canvasGroup, true);
            BluetoothLEHardwareInterface.ScanForPeripheralsWithServices(new string[] { BluetoothController.Instance.ServiceUUID },
                                                                        (address, name) =>
            {
                AddPeripheral(address, name);
            });
        }
        else
        {
            MyDebug.LogGreen("Peripheral Start Scaning!");
            BluetoothLEHardwareInterface.PeripheralName(GameManager.Instance.UserName);
            MyDebug.LogGreen("PeripheralName:" + GameManager.Instance.UserName);

            BluetoothLEHardwareInterface.CreateCharacteristic(BluetoothController.Instance.ReadUUID,
                                                              BluetoothLEHardwareInterface.CBCharacteristicProperties.CBCharacteristicPropertyRead |
                                                              BluetoothLEHardwareInterface.CBCharacteristicProperties.CBCharacteristicPropertyNotify,
                                                              BluetoothLEHardwareInterface.CBAttributePermissions.CBAttributePermissionsReadable, null, 0, null);
            MyDebug.LogGreen("CreateCharacteristic:Read!");

            BluetoothLEHardwareInterface.CreateCharacteristic(BluetoothController.Instance.WriteUUID,
                                                              BluetoothLEHardwareInterface.CBCharacteristicProperties.CBCharacteristicPropertyWrite,
                                                              BluetoothLEHardwareInterface.CBAttributePermissions.CBAttributePermissionsWriteable, null, 0,
                                                              BluetoothController.Instance.PeripheralReceiveMessage);
            MyDebug.LogGreen("CreateCharacteristic:Write!");

            BluetoothLEHardwareInterface.CreateService(BluetoothController.Instance.ServiceUUID, true, (message) =>
            {
                MyDebug.LogGreen("Create Service Success:" + message);
            });
            MyDebug.LogGreen("CreateService!");

            BluetoothLEHardwareInterface.StartAdvertising(() =>
            {
                MyDebug.LogGreen("Start Advertising!");
                bluetoothScanResultContent.SetActive(true);
                RefreshScanResultContent();
                StartCoroutine(AdvertisingCountDown());
                CommonTool.GuiHorizontalMove(bluetoothScanResultContent, Screen.width, MoveID.RightOrUp, canvasGroup, true);
            });
        }
    }
Exemplo n.º 18
0
        public static void EnsureDatabaseCreated(IServiceProvider services)
        {
            var context         = services.GetRequiredService <AutomaticaContext>();
            var visuInitFactory = services.GetRequiredService <IVisualisationFactory>();
            var config          = services.GetRequiredService <IConfiguration>();

            context.Database.Migrate();

            bool dbCreated = !context.BoardTypes.Any();

            if (dbCreated)
            {
                context.RuleInterfaceDirections.Add(new EF.Models.RuleInterfaceDirection()
                {
                    ObjId       = 1,
                    Name        = "Input",
                    Description = "Input",
                    Key         = "I"
                });
                context.RuleInterfaceDirections.Add(new EF.Models.RuleInterfaceDirection()
                {
                    ObjId       = 2,
                    Name        = "Output",
                    Description = "Output",
                    Key         = "O"
                });
                context.RuleInterfaceDirections.Add(new EF.Models.RuleInterfaceDirection()
                {
                    ObjId       = 3,
                    Name        = "Parameter",
                    Description = "Parameter",
                    Key         = "P"
                });

                context.RulePageTypes.Add(new RulePageType()
                {
                    ObjId       = 1,
                    Name        = "Rules",
                    Description = "Rules",
                    Key         = "rules"
                });
                context.VisuPageTypes.Add(new VisuPageType()
                {
                    ObjId       = 1,
                    Name        = "PC",
                    Description = "PC",
                    Key         = "pc"
                });
                context.VisuPageTypes.Add(new VisuPageType()
                {
                    ObjId       = 2,
                    Name        = "Mobile",
                    Description = "Mobile",
                    Key         = "mobile"
                });
                context.SaveChanges();

                context.Slaves.Add(new Slave()
                {
                    ObjId       = new Guid(ServerInfo.SelfSlaveId),
                    Name        = "local",
                    Description = "this is me",
                    ClientId    = "",
                    ClientKey   = ""
                });


                context.Settings.Add(new Setting
                {
                    ObjId     = 1,
                    ValueKey  = "ConfigVersion",
                    Type      = (long)PropertyTemplateType.Numeric,
                    Value     = 0,
                    Group     = "ConfigVersion",
                    IsVisible = false,
                    Order     = 10
                });
                context.SaveChanges();
            }

            var lat = context.Settings.SingleOrDefault(a => a.ValueKey == "Latitude");

            if (lat == null)
            {
                context.Settings.Add(new Setting
                {
                    ValueKey  = "Latitude",
                    Type      = (long)PropertyTemplateType.Numeric,
                    Value     = 0,
                    Group     = "SERVER.SETTINGS",
                    IsVisible = true,
                    Order     = 10
                });

                context.Settings.Add(new Setting
                {
                    ValueKey  = "Longitude",
                    Type      = (long)PropertyTemplateType.Numeric,
                    Value     = 0,
                    Group     = "SERVER.SETTINGS",
                    IsVisible = true,
                    Order     = 11
                });
            }
            else
            {
                var longi = context.Settings.SingleOrDefault(a => a.ValueKey == "Longitude");

                if (lat.ValueDouble == null)
                {
                    lat.ValueDouble = 0;
                }

                if (longi.ValueDouble == null)
                {
                    longi.ValueDouble = 0;
                }

                context.Settings.Update(longi);
                context.Settings.Update(lat);
            }

            var apiKey = context.Settings.SingleOrDefault(a => a.ValueKey == "apiKey");

            if (apiKey == null)
            {
                context.Settings.Add(new Setting
                {
                    ValueKey  = "apiKey",
                    Type      = (long)PropertyTemplateType.Text,
                    Value     = "",
                    Group     = "SERVER.SETTINGS",
                    IsVisible = true,
                    Order     = 0
                });
            }

            var autoUpdate      = context.Settings.SingleOrDefault(a => a.ValueKey == "autoUpdate");
            var autoUpdateTime  = context.Settings.SingleOrDefault(a => a.ValueKey == "autoUpdateTime");
            var reportCrashLogs = context.Settings.SingleOrDefault(a => a.ValueKey == "reportCrashLogs");

            if (autoUpdate == null)
            {
                context.Settings.Add(new Setting
                {
                    ValueKey  = "autoUpdate",
                    Type      = (long)PropertyTemplateType.Bool,
                    Value     = false,
                    Group     = "SERVER.SETTINGS",
                    IsVisible = true,
                    Order     = 20
                });
            }
            else
            {
                autoUpdate.Order = 20;
                context.Update(autoUpdate);
            }

            if (autoUpdateTime == null)
            {
                context.Settings.Add(new Setting
                {
                    ValueKey  = "autoUpdateTime",
                    Type      = (long)PropertyTemplateType.Time,
                    Value     = new DateTime(2000, 12, 31, 2, 0, 0),
                    Group     = "SERVER.SETTINGS",
                    IsVisible = true,
                    Order     = 21
                });
            }
            else
            {
                autoUpdateTime.Order = 21;
                autoUpdateTime.Type  = (long)PropertyTemplateType.Time;
                context.Update(autoUpdateTime);
            }

            if (reportCrashLogs == null)
            {
                context.Settings.Add(new Setting
                {
                    ValueKey  = "reportCrashLogs",
                    Type      = (long)PropertyTemplateType.Bool,
                    Value     = false,
                    Group     = "SERVER.SETTINGS",
                    IsVisible = true,
                    Order     = 22
                });
            }
            else
            {
                reportCrashLogs.Order = 22;
                context.Update(reportCrashLogs);
            }

            var cloudUrl = context.Settings.SingleOrDefault(a => a.ValueKey == "cloudUrl");

            if (cloudUrl == null)
            {
                context.Settings.Add(new Setting
                {
                    ValueKey  = "cloudUrl",
                    Type      = (long)PropertyTemplateType.Text,
                    Value     = "https://automatica-core-cloud.azurewebsites.net",
                    Group     = "SERVER.SETTINGS",
                    IsVisible = true,
                    Order     = 1
                });
            }

            var cloudEnvironment = context.Settings.SingleOrDefault(a => a.ValueKey == "cloudEnvironment");

            if (cloudEnvironment == null)
            {
                var cloudEnvironmentType = "master";
#if DEBUG
                cloudEnvironmentType = "develop";
#else
                cloudEnvironmentType = "master";
#endif

                context.Settings.Add(new Setting
                {
                    ValueKey  = "cloudEnvironment",
                    Type      = (long)PropertyTemplateType.Text,
                    Value     = cloudEnvironmentType,
                    Group     = "SERVER.SETTINGS",
                    IsVisible = true,
                    Order     = 2
                });
            }

            var projectName = context.Settings.SingleOrDefault(a => a.ValueKey == "projectName");

            if (projectName == null)
            {
                context.Settings.Add(new Setting
                {
                    ValueKey  = "projectName",
                    Type      = (long)PropertyTemplateType.Text,
                    Value     = "Automatica.Core",
                    Group     = "SERVER.SETTINGS",
                    IsVisible = true,
                    Order     = 3
                });
            }

            var propertyTypes = Enum.GetValues(typeof(PropertyTemplateType));

            foreach (var propertyType in propertyTypes)
            {
                var propertyTypeDb = context.PropertyTypes.SingleOrDefault(a => a.Type == Convert.ToInt64(propertyType));
                var isNewObject    = false;
                if (propertyTypeDb == null)
                {
                    propertyTypeDb = new PropertyType {
                        Type = (int)propertyType
                    };
                    isNewObject = true;
                }

                var type       = propertyType.GetType();
                var memInfo    = type.GetMember(propertyType.ToString());
                var attributes = memInfo[0].GetCustomAttributes(typeof(PropertyTemplateTypeAttribute), false);

                if (attributes.Length > 0 && attributes[0] is PropertyTemplateTypeAttribute attribute)
                {
                    propertyTypeDb.Name        = attribute.Name;
                    propertyTypeDb.Description = attribute.Description;
                    propertyTypeDb.Meta        = attribute.Meta;
                }
                else
                {
                    propertyTypeDb.Name        = propertyType.GetType().Name;
                    propertyTypeDb.Description = propertyType.GetType().Name;
                    propertyTypeDb.Meta        = null;
                }

                if (isNewObject)
                {
                    context.PropertyTypes.Add(propertyTypeDb);
                }
                else
                {
                    context.PropertyTypes.Update(propertyTypeDb);
                }
            }

            var nodeDataTypes = Enum.GetValues(typeof(NodeDataType));

            foreach (var nodeDataType in nodeDataTypes)
            {
                var nodeDataTypeDb = context.NodeDataTypes.SingleOrDefault(a => a.Type == Convert.ToInt64(nodeDataType));
                var isNewObject    = false;
                if (nodeDataTypeDb == null)
                {
                    nodeDataTypeDb      = new EF.Models.NodeDataType();
                    nodeDataTypeDb.Type = (int)nodeDataType;
                    isNewObject         = true;
                }

                var type       = nodeDataType.GetType();
                var memInfo    = type.GetMember(nodeDataType.ToString());
                var attributes = memInfo[0].GetCustomAttributes(typeof(NodeDataTypeEnumAttribute), false);

                if (attributes.Length > 0 && attributes[0] is NodeDataTypeEnumAttribute attribute)
                {
                    nodeDataTypeDb.Name        = attribute.Name;
                    nodeDataTypeDb.Description = attribute.Description;
                }
                else
                {
                    nodeDataTypeDb.Name        = nodeDataType.GetType().Name;
                    nodeDataTypeDb.Description = nodeDataType.GetType().Name;
                }

                if (isNewObject)
                {
                    context.NodeDataTypes.Add(nodeDataTypeDb);
                }
                else
                {
                    context.NodeDataTypes.Update(nodeDataTypeDb);
                }
            }


            context.SaveChanges();
            visuInitFactory.Initialize(context, config);
            context.SaveChanges();

            CreateInterfaceTypes(context);
            context.SaveChanges();

            AddSystemTemplates(context);

            IDatabaseBoardType boardType = null;

            if (BoardTypes.Docker.Docker.InDocker)
            {
                boardType = new BoardTypes.Docker.Docker();
            }
            else
            {
                boardType = new RaspberryPi();
            }

            ServerInfo.BoardType = boardType;

            AddBoard(context, boardType);

            AddAreaData(context);
            CategoryGroup.GenerateDefault(context);
            context.SaveChanges();
            CategoryInstance.GenerateDefault(context);

            context.SaveChanges();


            if (!context.AreaInstances.Any())
            {
                var projectInstance = new AreaInstance
                {
                    ObjId             = Guid.NewGuid(),
                    Name              = "Project",
                    Description       = "",
                    Icon              = "home",
                    This2AreaTemplate = AreaTemplateAttribute.GetFromEnum(AreaTemplates.Project),
                    This2Parent       = null
                };
                context.AreaInstances.Add(projectInstance);
            }

            if (dbCreated)
            {
                var rootNodeTemplate = context.NodeTemplates.SingleOrDefault(a => a.ObjId == GuidTemplateTypeAttribute.GetFromEnum(boardType.BoardType));
                var rootNode         = NodeInstanceFactory.CreateNodeInstanceFromTemplate(rootNodeTemplate);

                rootNode.Name        = boardType.Name;
                rootNode.Description = "";

                context.NodeInstances.Add(rootNode);

                var childs = context.NodeTemplates.Where(a => a.NeedsInterface2InterfacesType == rootNodeTemplate.ObjId);

                foreach (var child in childs)
                {
                    if (child.NeedsInterface2InterfacesType == child.ProvidesInterface2InterfaceType)
                    {
                        continue;
                    }
                    var node = NodeInstanceFactory.CreateNodeInstanceFromTemplate(child);
                    node.This2ParentNodeInstance = rootNode.ObjId;
                    context.NodeInstances.Add(node);
                }


                var rulePage = new RulePage
                {
                    ObjId             = Guid.NewGuid(),
                    Name              = "Page1",
                    Description       = "",
                    This2RulePageType = 1
                };

                context.RulePages.Add(rulePage);


                var visuPage = new VisuPage
                {
                    ObjId             = Guid.NewGuid(),
                    Name              = "Page1",
                    Description       = "",
                    This2VisuPageType = 2,
                    DefaultPage       = true
                };

                context.VisuPages.Add(visuPage);

                AddInitUserManagementData(context);

                context.SaveChanges();
            }


            context.SaveChanges();
        }
Exemplo n.º 19
0
 public void DownloadRecord(CategoryInstance instance, System.Action <ArrayList> OnSucceed, System.Action <string> OnFail)
 {
     StartCoroutine(c_RankCtrl.DownloadRecord(instance, OnSucceed, OnFail));
 }