Ejemplo n.º 1
0
        public static async Task <bool> ChooseString(uint index)
        {
            if (!SelectString.IsOpen)
            {
                return(false);
            }

            var lines = SelectString.Lines();

            int ticks = 0;

            while (ticks < 20 && SelectString.IsOpen)
            {
                SelectString.ClickSlot(index);
                await Coroutine.Sleep(500);

                ticks++;

                var current = SelectString.Lines();
                if (!lines.SequenceEqual(current))
                {
                    break;
                }
            }

            return(true);
        }
Ejemplo n.º 2
0
        public async Task <bool> Run()
        {
            if (CommonBehaviors.IsLoading)
            {
                await Coroutine.Wait(-1, () => !CommonBehaviors.IsLoading);

                return(true);
            }

            if (QuestLogManager.InCutscene)
            {
                TreeRoot.StatusText = "InCutscene";
                if (AgentCutScene.Instance != null)
                {
                    AgentCutScene.Instance.PromptSkip();
                    await Coroutine.Wait(250, () => SelectString.IsOpen);

                    if (SelectString.IsOpen)
                    {
                        SelectString.ClickSlot(0);
                    }

                    return(true);
                }
            }

            if (Talk.DialogOpen)
            {
                Talk.Next();
                return(true);
            }

            return(false);
        }
Ejemplo n.º 3
0
        protected override async Task <bool> RunAsync()
        {
            if (CommonBehaviors.IsLoading)
            {
                await Coroutine.Wait(Timeout.Infinite, () => !CommonBehaviors.IsLoading);
            }

            if (QuestLogManager.InCutscene)
            {
                AgentCutScene cutscene = AgentCutScene.Instance;
                if (cutscene != null && cutscene.CanSkip)
                {
                    cutscene.PromptSkip();

                    await Coroutine.Wait(1000, () => SelectString.IsOpen);

                    if (SelectString.IsOpen)
                    {
                        SelectString.ClickSlot(0);
                    }
                }
            }

            if (IsInInstance)
            {
                if (!IsDutyCommenced)
                {
                    await Coroutine.Wait(TimeSpan.FromMinutes(5), () => IsDutyCommenced);
                }
            }

            return(false);
        }
Ejemplo n.º 4
0
        private void CloseWindows()
        {
            if (SelectYesno.IsOpen)
            {
                SelectYesno.ClickNo();
            }

            if (Request.IsOpen)
            {
                Request.Cancel();
            }

            if (JournalResult.IsOpen)
            {
                JournalResult.Decline();
            }

            if (SelectString.IsOpen)
            {
                SelectString.ClickSlot(uint.MaxValue);
            }

            if (SelectIconString.IsOpen)
            {
                SelectIconString.ClickSlot(uint.MaxValue);
            }

            if (Shop.Open)
            {
                Shop.Close();
            }
        }
Ejemplo n.º 5
0
        public static async Task <bool> OpenFCCraftingStation()
        {
            if (GameObjectManager.GetObjectByNPCId(2005238) == null)
            {
                Logging.Write("Can't find Fabrication Station");
                return(false);
            }

            var station = GameObjectManager.GetObjectByNPCId(2005238);

            if (!station.IsWithinInteractRange)
            {
                var _target = station.Location;
                Navigator.PlayerMover.MoveTowards(_target);
                while (_target.Distance2D(Core.Me.Location) >= 4)
                {
                    Navigator.PlayerMover.MoveTowards(_target);
                    await Coroutine.Sleep(100);
                }

                Navigator.PlayerMover.MoveStop();
            }

            station.Interact();

            await Coroutine.Wait(5000, () => SelectString.IsOpen);

            SelectString.ClickSlot(0);

            await Coroutine.Wait(5000, () => SubmarinePartsMenu.Instance.IsOpen);

            return(SubmarinePartsMenu.Instance.IsOpen);
        }
Ejemplo n.º 6
0
 protected override Composite CreateBehavior()
 {
     return(new PrioritySelector(
                new Decorator(ret => !doneEmote && !string.IsNullOrWhiteSpace(Emote),
                              new Action(r =>
     {
         GameObjectManager.GetObjectByNPCId((uint)NpcId).Target();
         ChatManager.SendChat("/" + Emote);
         doneEmote = true;
     })
                              ),
                new Decorator(ret => SelectYesno.IsOpen,
                              new Action(r =>
     {
         SelectYesno.ClickYes();
     })
                              ),
                new Decorator(ret => SelectString.IsOpen,
                              new Action(r =>
     {
         SelectString.ClickSlot((uint)DialogOption);
     })
                              ),
                base.CreateBehavior()
                ));
 }
Ejemplo n.º 7
0
 protected override Composite CreateBehavior()
 {
     return(new PrioritySelector(
                CommonBehaviors.HandleLoading,
                new Decorator(ret => QuestId == 65888 && SelectYesno.IsOpen,
                              new Action(r =>
     {
         SelectYesno.ClickYes();
     })
                              ),
                new Decorator(ret => QuestId == 65889 && SelectString.IsOpen,
                              new Action(r =>
     {
         SelectString.ClickSlot(0);
     })
                              ),
                new Decorator(ret => QuestId == 67137 && SelectString.IsOpen,
                              new Action(r =>
     {
         SelectString.ClickSlot(0);
     })
                              ),
                new Decorator(ret => QuestId == 68612 && SelectYesno.IsOpen,
                              new Action(r =>
     {
         SelectYesno.ClickYes();
     })
                              ),
                base.CreateBehavior()
                ));
 }
Ejemplo n.º 8
0
 protected override Composite CreateBehavior()
 {
     return(new PrioritySelector(
                new Decorator(ret => QuestId == 65997 && SelectYesno.IsOpen,
                              new Action(r =>
     {
         SelectYesno.ClickYes();
     })
                              ),
                new Decorator(ret => QuestId == 66182 && SelectYesno.IsOpen,
                              new Action(r =>
     {
         SelectYesno.ClickYes();
     })
                              ),
                new Decorator(ret => QuestId == 66856 && SelectString.IsOpen,
                              new Action(r =>
     {
         SelectString.ClickSlot(1);
     })
                              ),
                new Decorator(ret => QuestId == 67019 && SelectYesno.IsOpen,
                              new Action(r =>
     {
         SelectYesno.ClickYes();
     })
                              ),
                new Decorator(ret => QuestId == 67238 && SelectString.IsOpen,
                              new Action(r =>
     {
         SelectString.ClickSlot(0);
     })
                              ),
                new Decorator(ret => QuestId == 68271 && SelectYesno.IsOpen,
                              new Action(r =>
     {
         SelectYesno.ClickYes();
     })
                              ),
                new Decorator(ret => QuestId == 68299 && SelectString.IsOpen,
                              new Action(r =>
     {
         SelectString.ClickSlot(0);
     })
                              ),
                new Decorator(ret => QuestId == 68407 && SelectString.IsOpen,
                              new Action(r =>
     {
         SelectString.ClickSlot(0);
     })
                              ),
                new Decorator(ret => QuestId == 68487 && SelectYesno.IsOpen,
                              new Action(r =>
     {
         SelectYesno.ClickYes();
     })
                              ),
                base.CreateBehavior()
                ));
 }
Ejemplo n.º 9
0
 protected override Composite CreateBehavior()
 {
     return(new PrioritySelector(
                new Decorator(ret => SelectYesno.IsOpen,
                              new Action(r =>
     {
         SelectYesno.ClickYes();
     })
                              ),
                new Decorator(ret => SelectString.IsOpen,
                              new Action(r =>
     {
         if (selectStringIndex.Count > 0)
         {
             SelectString.ClickSlot((uint)selectStringIndex.Dequeue());
         }
         else
         {
             SelectString.ClickSlot(0);
         }
     })
                              ),
                base.CreateBehavior()
                ));
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Will skip cutscenes by trying to exit out of them or advance the dialogue.
        /// </summary>
        /// <returns></returns>
        private async Task <bool> ExecuteSkipCutscene()
        {
            if (!QuestLogManager.InCutscene)
            {
                return(false);
            }

            // Try to skip the cutscene
            if (WaitHelper.Instance.IsDoneWaiting("SkipCutscene", new TimeSpan(0, 0, 1), true))
            {
                AgentCutScene.Instance.PromptSkip();
                return(true);
            }

            if (AgentCutScene.Instance.CanSkip && SelectString.IsOpen)
            {
                SelectString.ClickSlot(0);
                LogHelper.Instance.Log("Skipping Cutscene...");
                return(true);
            }

            //// If that is not an option, at least try to forward it as fast as possible...
            //if (Talk.DialogOpen)
            //{
            //	Talk.Next();
            //	return true;
            //}


            return(false);
        }
Ejemplo n.º 11
0
        public static async Task OpenHousingWards()
        {
            if (SelectString.IsOpen)
            {
                SelectString.ClickLineContains("Go to specified");

                await Coroutine.Wait(5000, () => HousingSelectBlock.Instance.IsOpen);
            }
        }
Ejemplo n.º 12
0
 public static bool OpenInventory()
 {
     if (IsOpen)
     {
         return(SelectString.ClickLineEquals(RetainerTaskStrings.Inventory));
     }
     Logging.Write("Retainer task window not open");
     return(false);
 }
Ejemplo n.º 13
0
        public static bool CloseTasks()
        {
            if (IsOpen)
            {
                SelectString.ClickSlot((uint)(SelectString.LineCount - 1));
            }

            return(!IsOpen);
        }
Ejemplo n.º 14
0
        public static bool CloseTasks()
        {
            if (!IsOpen)
            {
                return(true);
            }

            return(SelectString.ClickLineEquals(RetainerTaskStrings.Quit));
        }
Ejemplo n.º 15
0
        private async Task BuyScrip(int itemId, int count, int selectString)
        {
            await Coroutine.Sleep(500);



            var unit = GameObjectManager.GetObjectsByNPCIds <Character>(npcIds).OrderBy(r => r.Distance()).FirstOrDefault();

            if (unit == null)
            {
                _isDone = true;
                return;
            }

            if (!ShopExchangeCurrency.Open && unit.Location.Distance(Core.Me.Location) > 4f)
            {
                await Navigation.OffMeshMove(unit.Location);

                await Coroutine.Sleep(500);
            }

            unit.Interact();

            await Coroutine.Wait(5000, () => SelectIconString.IsOpen);

            if (SelectIconString.IsOpen)
            {
                SelectIconString.ClickSlot((uint)0);

                await Coroutine.Wait(5000, () => SelectString.IsOpen);

                SelectString.ClickSlot((uint)selectString);

                await Coroutine.Wait(5000, () => ShopExchangeCurrency.Open);

                if (ShopExchangeCurrency.Open)
                {
                    ShopExchangeCurrency.Purchase((uint)itemId, (uint)count);

                    await Coroutine.Wait(5000, () => SelectYesno.IsOpen);

                    SelectYesno.ClickYes();

                    await Coroutine.Sleep(1000);

                    ShopExchangeCurrency.Close();

                    await Coroutine.Wait(5000, () => SelectString.IsOpen);

                    SelectString.ClickSlot((uint)(SelectString.LineCount - 1));

                    await Coroutine.Wait(5000, () => SelectString.IsOpen);
                }
            }

            _isDone = true;
        }
 protected override Composite CreateBehavior()
 {
     return(new PrioritySelector(
                new Decorator(ret => QuestId == 65715 && SelectYesno.IsOpen,
                              new Action(r =>
     {
         SelectYesno.ClickYes();
     })
                              ),
                new Decorator(ret => QuestId == 65789 && SelectYesno.IsOpen,
                              new Action(r =>
     {
         SelectYesno.ClickYes();
     })
                              ),
                new Decorator(ret => QuestId == 66046 && SelectString.IsOpen,
                              new Action(r =>
     {
         SelectString.ClickSlot(0);
     })
                              ),
                new Decorator(ret => QuestId == 67023 && SelectString.IsOpen,
                              new Action(r =>
     {
         SelectString.ClickSlot(0);
     })
                              ),
                new Decorator(ret => QuestId == 67201 && SelectString.IsOpen,
                              new Action(r =>
     {
         SelectString.ClickSlot(0);
     })
                              ),
                new Decorator(ret => QuestId == 67254 && SelectString.IsOpen,
                              new Action(r =>
     {
         SelectString.ClickSlot(0);
     })
                              ),
                new Decorator(ret => QuestId == 67591 && SelectString.IsOpen,
                              new Action(r =>
     {
         SelectString.ClickSlot(0);
     })
                              ),
                new Decorator(ret => QuestId == 67670 && SelectString.IsOpen,
                              new Action(r =>
     {
         SelectString.ClickSlot(0);
     })
                              ),
                base.CreateBehavior()
                ));
 }
Ejemplo n.º 17
0
        public int CompareTo(object obj)
        {
            var sel = obj as VMSelectable;

            if (null == sel)
            {
                return(-1);
            }

            return(SelectString.CompareTo(sel.SelectString));
        }
Ejemplo n.º 18
0
        public static bool OpenInventory()
        {
            if (IsOpen)
            {
                SelectString.ClickSlot(0);
                return(true);
            }

            Logging.Write("Retainer task window not open");
            return(false);
        }
Ejemplo n.º 19
0
        internal static async Task <bool> Main(uint aetheryteId)
        {
            Logger.SendLog("Binding to the aetheryte crystal.");
            var aetheryteObject = GetAetheryteObject(aetheryteId);

            if (aetheryteObject == null)
            {
                Logger.SendErrorLog("Could not find an aetheryte crystal.");
                return(false);
            }

            if (!WorldManager.CanFly)
            {
                var movementParams = new MoveToParameters
                {
                    Destination       = "Aetheryte crystal",
                    Location          = aetheryteObject.Location,
                    DistanceTolerance = 8f
                };

                while (aetheryteObject.Distance(Core.Player) > 8f)
                {
                    Navigator.MoveTo(movementParams);
                    await Coroutine.Yield();
                }

                Navigator.Stop();
            }
            else
            {
                while (aetheryteObject.Distance(Core.Player) > 8f)
                {
                    Core.Player.Face(aetheryteObject);
                    Navigator.PlayerMover.MoveTowards(aetheryteObject.Location);
                    await Coroutine.Yield();
                }

                Navigator.PlayerMover.MoveStop();
            }

            aetheryteObject.Interact();
            await Coroutine.Sleep(MainSettings.Instance.ActionDelay);

            SelectString.ClickLineContains("Set Home Point");
            await Coroutine.Sleep(MainSettings.Instance.ActionDelay);

            SelectYesno.ClickYes();
            await Coroutine.Sleep(MainSettings.Instance.ActionDelay);

            Logger.SendLog("Home point bound successfully.");

            return(true);
        }
Ejemplo n.º 20
0
 protected override Composite CreateBehavior()
 {
     return(new PrioritySelector(
                new Decorator(ret => SelectString.IsOpen,
                              new Action(r =>
     {
         SelectString.ClickSlot((uint)DialogOption);
     })
                              ),
                base.CreateBehavior()
                ));
 }
Ejemplo n.º 21
0
        private async Task <bool> CloseSelectString(ushort interval = 250)
        {
            await Coroutine.Wait(1000, () => SelectString.IsOpen);

            if (SelectString.IsOpen)
            {
                SelectString.ClickSlot((uint)SelectString.LineCount - 1);
            }

            await Coroutine.Wait(1000, () => !SelectString.IsOpen);

            return(!SelectString.IsOpen);
        }
Ejemplo n.º 22
0
        /// <inheritdoc/>
        public override async Task <bool> Run()
        {
            if (CommonBehaviors.IsLoading)
            {
                StatusBar.Text = Translations.STATUS_LOADING_WAIT;
                Logger.LogInformation(Translations.STATUS_LOADING_WAIT);

                await Coroutine.Wait(Timeout.Infinite, () => !CommonBehaviors.IsLoading);

                return(HANDLED_EXECUTION);
            }

            if (QuestLogManager.InCutscene)
            {
                StatusBar.Text = Translations.STATUS_CUTSCENE_WAIT;
                Logger.LogInformation(Translations.STATUS_CUTSCENE_WAIT);

                AgentCutScene cutscene = AgentCutScene.Instance;
                if (cutscene != null && cutscene.CanSkip)
                {
                    cutscene.PromptSkip();
                    await Coroutine.Wait(500, () => SelectString.IsOpen);

                    if (SelectString.IsOpen)
                    {
                        Logger.LogInformation(Translations.LOG_CUTSCENE_SKIPPING);

                        SelectString.ClickSlot(0);
                    }

                    return(HANDLED_EXECUTION);
                }
            }

            if (CurrentInstance.IsInInstance)
            {
                if (!CurrentInstance.IsDutyCommenced)
                {
                    StatusBar.Text = Translations.STATUS_DUTY_WAIT_COMMENCED;
                    Logger.LogInformation(Translations.STATUS_DUTY_WAIT_COMMENCED);

                    await Coroutine.Wait(TimeSpan.FromMinutes(2), () => CurrentInstance.IsDutyCommenced);

                    Logger.LogInformation(Translations.LOG_DUTY_COMMENCED, CurrentInstance.Id, CurrentInstance.Name);

                    return(HANDLED_EXECUTION);
                }
            }

            return(PASS_EXECUTION);
        }
 /// <summary>
 /// Creates an array of <see cref="T:Ferda.Modules.SelectString"/> from
 /// specified array of <see cref="T:System.String">Strings</see> (<c>input</c>).
 /// </summary>
 /// <param name="input">Input array of <see cref="T:System.String">Strings</see>.</param>
 /// <returns>Output array of <see cref="T:Ferda.Modules.SelectString"/>.</returns>
 public static SelectString[] StringArrayToSelectStringArray(string[] input)
 {
     if ((input == null) || (input.Length == 0))
         return new SelectString[0];
     List<SelectString> result = new List<SelectString>();
     foreach (string item in input)
     {
         SelectString selectString = new SelectString();
         selectString.name = item;
         selectString.label = item;
         result.Add(selectString);
     }
     return result.ToArray();
 }
Ejemplo n.º 24
0
        public static void SelectQuit()
        {
            uint line;

            if (SelectString.IsOpen)
            {
                line = (uint)(SelectString.LineCount - 1);
                SelectString.ClickSlot(line);
            }
            else if (SelectIconString.IsOpen)
            {
                line = (uint)(SelectIconString.LineCount - 1);
                SelectIconString.ClickSlot(line);
            }
        }
Ejemplo n.º 25
0
 public static void SelectLine(uint line)
 {
     if (SelectString.IsOpen)
     {
         SelectString.ClickSlot(line);
     }
     else if (SelectIconString.IsOpen)
     {
         SelectIconString.ClickSlot(line);
     }
     else if (CutSceneSelectString.IsOpen)
     {
         CutSceneSelectString.ClickSlot(line);
     }
 }
Ejemplo n.º 26
0
        protected async Task <bool> ShortCircuit(GameObject obj, int timeout = 0)
        {
            var Timer = new Stopwatch();

            while (obj.IsTargetable && obj.IsVisible || QuestLogManager.InCutscene)
            {
                if (timeout > 0)
                {
                    Timer.Start();
                }

                if (!QuestLogManager.InCutscene && timeout > 0 && Timer.ElapsedMilliseconds >= timeout)
                {
                    Timer.Stop();
                    return(false);
                }

                if (IsDone)
                {
                    return(false);
                }

                if (Talk.DialogOpen)
                {
                    Talk.Next();
                    await Coroutine.Sleep(100);
                }

                if (QuestLogManager.InCutscene)
                {
                    if (AgentCutScene.Instance.CanSkip && !SelectString.IsOpen)
                    {
                        AgentCutScene.Instance.PromptSkip();
                        if (await Coroutine.Wait(600, () => SelectString.IsOpen))
                        {
                            SelectString.ClickSlot(0);
                            await Coroutine.Sleep(1000);
                        }
                    }
                }

                await Coroutine.Yield();
            }

            return(false);
        }
Ejemplo n.º 27
0
        public async Task <bool> GetHuntOrderType(uint orderType)
        {
            if (GetNpc == null || !GetNpc.IsWithinInteractRange)
            {
                //Navigation.LogCritical("GoTo");
                await GetTo();
            }

            uint slot = 0;

            for (int i = 0; i < OrderTypes.Length; i++)
            {
                if (OrderTypes[i] != orderType)
                {
                    continue;
                }

                slot = (uint)i;
                break;
            }

            if (GetNpc == null || !GetNpc.IsWithinInteractRange)
            {
                return(false);
            }

            var unit = GetNpc;

            unit.Target();
            unit.Interact();
            await Coroutine.Wait(5000, () => SelectString.IsOpen);

            if (!SelectString.IsOpen)
            {
                return(false);
            }
            SelectString.ClickSlot(slot);
            await Coroutine.Wait(5000, () => Mobhunt.Instance.IsOpen);

            Navigation.LogCritical($"is open {Mobhunt.Instance.IsOpen}");
            Mobhunt.Instance.Accept();
            Navigation.LogCritical($"accepted");
            await Coroutine.Sleep(1000);

            return(HuntHelper.GetAcceptedHunts()[orderType]);
        }
Ejemplo n.º 28
0
        public override string ToTable(int top = 0)
        {
            var strFields = SelectString.Length == 0 ? "*" : SelectString.ToString();

            var topString = new StringBuilder();

            if (top > 0)
            {
                if (WhereString.Length > 0)
                {
                    topString.Append(" AND ");
                }
                topString.Append(string.Format("ROWNUM <= {0}", top));
            }
            return(string.Format("SELECT {0} FROM {1} {2} {3} {4};", GetFields(), TableName, WhereString, topString,
                                 SortString));
        }
Ejemplo n.º 29
0
        private static async Task CloseHousingWardsNoLoad()
        {
            if (HousingSelectBlock.Instance.IsOpen)
            {
                HousingSelectBlock.Instance.Close();

                await Coroutine.Wait(5000, () => SelectString.IsOpen);

                if (SelectString.IsOpen)
                {
                    SelectString.ClickSlot((uint)(SelectString.LineCount - 1));
                    await Coroutine.Wait(5000, () => !SelectString.IsOpen);
                }

                await Coroutine.Sleep(500);
            }
        }
Ejemplo n.º 30
0
        public static async Task OpenHousingWards()
        {
            if (SelectString.IsOpen)
            {
                if (Translator.Language == Language.Chn)
                {
                    SelectString.ClickLineContains("移动到指定小区");
                }
                else
                {
                    SelectString.ClickLineContains("Go to specified");
                }


                await Coroutine.Wait(5000, () => HousingSelectBlock.Instance.IsOpen);
            }
        }
Ejemplo n.º 31
0
        public static async Task <bool> CloseFCCraftingStation()
        {
            if (!SubmarinePartsMenu.Instance.IsOpen)
            {
                return(true);
            }

            SubmarinePartsMenu.Instance.Close();

            await Coroutine.Wait(5000, () => SelectString.IsOpen);

            SelectString.ClickSlot(3);

            await Coroutine.Sleep(500);

            return(SelectString.IsOpen);
        }
        /// <summary>
        /// Generates the attribute.
        /// </summary>
        /// <param name="connectionString">The connection string.</param>
        /// <param name="dataMatrixName">Name of the data matrix.</param>
        /// <param name="columnSelectExpression">The column select expression.</param>
        /// <param name="boxIdentity">The box identity.</param>
        /// <returns>Generated attribute.</returns>
        public static GeneratedAttribute Generate(
			string connectionString,
			string dataMatrixName,
			string columnSelectExpression,
			string boxIdentity)
        {
            DataTable dataTable = Ferda.Modules.Helpers.Data.Column.GetDistincts(connectionString, dataMatrixName, columnSelectExpression, boxIdentity);
            CategoriesStruct categoriesStructValue = new CategoriesStruct();
            List<SelectString> categoriesNames = new List<SelectString>();
            categoriesStructValue.enums = new EnumCategorySeq();
            string rowValue;
            string categoryName;
            SelectString item;
            bool getNames = (dataTable.Rows.Count <= AbstractAttributeConstants.MaxLengthOfCategoriesNamesSelectStringArray);
            string includeNullCategoryNameValue = null;
            foreach (DataRow dataRow in dataTable.Rows)
            {
                rowValue = dataRow.ItemArray[0].ToString();
                if (String.IsNullOrEmpty(rowValue))
                {
                    categoryName = Ferda.Modules.Helpers.Common.Constants.DbNullCategoryName;
                    includeNullCategoryNameValue = categoryName;
                }
                else
                {
                    categoryName = rowValue;
                }
                categoriesStructValue.enums.Add(categoryName, new string[1] { rowValue });
                if (getNames)
                {
                    item = new SelectString();
                    item.label = categoryName;
                    item.name = categoryName;
                    categoriesNames.Add(item);
                }
            }
            GeneratedAttribute output = new GeneratedAttribute(
                categoriesStructValue,
                includeNullCategoryNameValue,
                categoriesStructValue.enums.Count,
                categoriesNames.ToArray());
            return output;
        }
Ejemplo n.º 33
0
        /// <summary>
        /// Gets the properties of the box module.
        /// </summary>
        /// <param name="localePrefs">The localization preferences.</param>
        /// <returns>
        /// Array of <seealso cref="T:Ferda.Modules.PropertyInfo">PropertyInfos</seealso>.
        /// </returns>
        public PropertyInfo[] GetProperties(string[] localePrefs)
        {
            List<PropertyInfo> result = new List<PropertyInfo>();
            List<SelectString> selectStrings = new List<SelectString>();
            Dictionary<string, string> selectStringsXL = new Dictionary<string, string>();
            Boxes.Serializer.Localization.IHelper boxLocalization = getLocalization(localePrefs);
            foreach (Boxes.Serializer.Configuration.Property property in this.box.Properties.Values)
            {
                //gets name of category where the proprety belongs to
                string categoryName = String.Empty;
                if (!String.IsNullOrEmpty(property.CategoryName))
                    categoryName = boxLocalization.PropertyCategories[property.CategoryName];

                //gets selectbox options (only for static selectboxes)
                SelectString[] selectBoxParams = null;
                if (property.SelectOptions != null && property.SelectOptions.Length > 0)
                {
                    foreach (Boxes.Serializer.Configuration.SelectOption selectBoxItem in property.SelectOptions)
                    {
                        SelectString selectString = new SelectString();
                        selectString.name = selectBoxItem.Name;
                        selectString.disableProperties = selectBoxItem.DisableProperties;
                        selectString.label = boxLocalization.GetSelectBoxOption(property.Name, selectBoxItem.Name, true).Label;
                        selectStrings.Add(selectString);
                    }
                    selectBoxParams = selectStrings.ToArray();
                    selectStrings.Clear();
                }
                if (selectBoxParams == null)
                    selectBoxParams = new SelectString[0];

                PropertyInfo resultItem = new PropertyInfo(
                    property.Name,
                    categoryName,
                    property.TypeClassIceId,
                    selectBoxParams,
                    property.Visible,
                    property.ReadOnly,
                    GetPropertyRestrictions(property.Name).ToArray(),
                    GetPropertyRegexp(property.Name),
                    property.SettingModuleIdentifier);
                result.Add(resultItem);
            }
            return result.ToArray();
        }
        /// <summary>
        /// Generates the the attribute.
        /// </summary>
        /// <param name="domainType">Type of the domain.</param>
        /// <param name="from">From.</param>
        /// <param name="to">To.</param>
        /// <param name="countOfCategories">The count of categories.</param>
        /// <param name="columnInfo">The column info.</param>
        /// <param name="boxIdentity">The box identity.</param>
        /// <returns>Generated attribute.</returns>
        public static GeneratedAttribute Generate(
			AttributeDomainEnum domainType,
			double from,
			double to,
			long countOfCategories,
			Ferda.Modules.Boxes.DataMiningCommon.Column.ColumnInfo columnInfo,
			string boxIdentity)
        {
            Ferda.Modules.Helpers.Data.Column.ValueType simpleColumnType = Ferda.Modules.Helpers.Data.Column.GetColumnValueTypeByValueSubType(columnInfo.columnSubType);
            if (simpleColumnType != Ferda.Modules.Helpers.Data.Column.ValueType.Integral
                && simpleColumnType != Ferda.Modules.Helpers.Data.Column.ValueType.Floating)
                throw Ferda.Modules.Exceptions.BadParamsError(null, boxIdentity, simpleColumnType.ToString(), restrictionTypeEnum.DbColumnDataType);

            //dataArray.Add(new Data(currentValue, currentCount));
            ArrayList dataArray = new ArrayList();
            DataTable frequencies = null;
            float startValue = Convert.ToSingle(columnInfo.statistics.ValueMin);
            float endValue = Convert.ToSingle(columnInfo.statistics.ValueMax);
            switch (domainType)
            {
                case AttributeDomainEnum.WholeDomain:
                    frequencies = Ferda.Modules.Helpers.Data.Column.GetDistinctsAndFrequencies(
                        columnInfo.dataMatrix.database.odbcConnectionString,
                        columnInfo.dataMatrix.dataMatrixName,
                        columnInfo.columnSelectExpression,
                        boxIdentity);
                    from = to = 0;
                    break;
                case AttributeDomainEnum.SubDomainValueBounds:
                    frequencies = Ferda.Modules.Helpers.Data.Column.GetDistinctsAndFrequencies(
                        columnInfo.dataMatrix.database.odbcConnectionString,
                        columnInfo.dataMatrix.dataMatrixName,
                        columnInfo.columnSelectExpression,
                        columnInfo.columnSelectExpression + ">=" + from + " AND " + columnInfo.columnSelectExpression + "<=" + to,
                        boxIdentity);
                    startValue = (float)from;
                    endValue = (float)to;
                    from = to = 0;
                    break;
                case AttributeDomainEnum.SubDomainNumberOfValuesBounds:
                    frequencies = Ferda.Modules.Helpers.Data.Column.GetDistinctsAndFrequencies(
                        columnInfo.dataMatrix.database.odbcConnectionString,
                        columnInfo.dataMatrix.dataMatrixName,
                        columnInfo.columnSelectExpression,
                        boxIdentity);
                    break;
                default:
                    throw Ferda.Modules.Exceptions.SwitchCaseNotImplementedError(domainType);
            }

            if (from < 0)
            {
                throw Ferda.Modules.Exceptions.BadValueError(null, boxIdentity, null, new string[] { "From" }, restrictionTypeEnum.Minimum);
            }
            if (to < 0)
            {
                throw Ferda.Modules.Exceptions.BadValueError(null, boxIdentity, null, new string[] { "To" }, restrictionTypeEnum.Minimum);
            }
            int fromUi = (int)from;
            int toUi = (int)to;
            int frequenciesCount = frequencies.Rows.Count;
            if (frequenciesCount <= from + to)
                return new GeneratedAttribute();
            object item;

            switch (simpleColumnType)
            {
                case Ferda.Modules.Helpers.Data.Column.ValueType.Floating:
                    for (int i = fromUi; i < (frequenciesCount - toUi); i++)
                    {
                        item = frequencies.Rows[i][Ferda.Modules.Helpers.Data.Column.SelectDistincts];
                        if (item == System.DBNull.Value)
                            continue;
                        dataArray.Add(new EquifrequencyIntervalGenerator.Data(Convert.ToSingle(item), Convert.ToInt32(frequencies.Rows[i][Ferda.Modules.Helpers.Data.Column.SelectFrequency])));
                    }
                    break;
                case Ferda.Modules.Helpers.Data.Column.ValueType.Integral:
                    for (int i = fromUi; i < (frequenciesCount - toUi); i++)
                    {
                        item = frequencies.Rows[i][Ferda.Modules.Helpers.Data.Column.SelectDistincts];
                        if (item == System.DBNull.Value)
                            continue;
                        dataArray.Add(new EquifrequencyIntervalGenerator.Data(Convert.ToInt64(item), Convert.ToInt32(frequencies.Rows[i][Ferda.Modules.Helpers.Data.Column.SelectFrequency])));
                    }
                    break;
                default:
                    throw Ferda.Modules.Exceptions.BadParamsError(null, boxIdentity, simpleColumnType.ToString(), restrictionTypeEnum.DbColumnDataType);
            }
            object[] splitPoints = null;
            try
            {
                splitPoints = EquifrequencyIntervalGenerator.GenerateIntervals((int)countOfCategories, dataArray);
            }
            catch (ArgumentOutOfRangeException ex)
            {
                if (ex.ParamName == "intervals")
                {
                    throw Ferda.Modules.Exceptions.BadValueError(ex, boxIdentity, null, new string[] { "CountOfCategories" }, restrictionTypeEnum.Other);
                }
                else
                    throw ex;
            }
            if (splitPoints == null)
                return new GeneratedAttribute();

            CategoriesStruct categoriesStruct = new CategoriesStruct();

            string categoryName;
            List<SelectString> categoriesNames = new List<SelectString>();
            SelectString categoriesNamesItem;
            bool computeCategoriesNames = (splitPoints.Length + 1 < Ferda.Modules.Boxes.DataMiningCommon.Attributes.AbstractAttributeConstants.MaxLengthOfCategoriesNamesSelectStringArray);
            switch (simpleColumnType)
            {
                case Ferda.Modules.Helpers.Data.Column.ValueType.Floating:
                    categoriesStruct.floatIntervals = new FloatIntervalCategorySeq();
                    float beginValueFl = startValue;
                    float nextValueFl;
                    FloatIntervalStruct intervalFlTemplate = new FloatIntervalStruct();
                    intervalFlTemplate.leftBoundType = BoundaryEnum.Sharp;
                    intervalFlTemplate.rightBoundType = BoundaryEnum.Round;
                    FloatIntervalStruct intervalFl;
                    for (int i = 0; i < splitPoints.Length + 1; i++)
                    {
                        if (i == splitPoints.Length)
                        {
                            nextValueFl = endValue;
                            intervalFlTemplate.rightBoundType = BoundaryEnum.Sharp;
                        }
                        else
                            nextValueFl = (float)splitPoints[i];
                        intervalFl = intervalFlTemplate;
                        intervalFl.leftBound = beginValueFl;
                        intervalFl.rightBound = nextValueFl;
                        categoryName = Constants.LeftClosedInterval + beginValueFl.ToString() + Constants.SeparatorInterval + nextValueFl.ToString();
                        categoryName += (intervalFl.rightBoundType == BoundaryEnum.Sharp)? Constants.RightClosedInterval : Constants.RightOpenedInterval;

                        if (computeCategoriesNames)
                        {
                            categoriesNamesItem = new SelectString();
                            categoriesNamesItem.name = categoryName;
                            categoriesNamesItem.label = categoryName;
                            categoriesNames.Add(categoriesNamesItem);
                        }

                        categoriesStruct.floatIntervals.Add(
                            categoryName,
                            new FloatIntervalStruct[] { intervalFl });
                        beginValueFl = nextValueFl;
                    }

                    return new GeneratedAttribute(
                        categoriesStruct,
                        null,
                        categoriesStruct.floatIntervals.Count,
                        categoriesNames.ToArray());
                case Ferda.Modules.Helpers.Data.Column.ValueType.Integral:
                    categoriesStruct.longIntervals = new LongIntervalCategorySeq();
                    long beginValueLn = (long)startValue;
                    long nextValueLn;
                    LongIntervalStruct intervalLnTemplate = new LongIntervalStruct();
                    intervalLnTemplate.leftBoundType = BoundaryEnum.Sharp;
                    intervalLnTemplate.rightBoundType = BoundaryEnum.Round;
                    LongIntervalStruct intervalLn;
                    for (int i = 0; i < splitPoints.Length + 1; i++)
                    {
                        if (i == splitPoints.Length)
                        {
                            nextValueLn = (long)endValue;
                            intervalLnTemplate.rightBoundType = BoundaryEnum.Sharp;
                        }
                        else
                            nextValueLn = (long)splitPoints[i];
                        intervalLn = intervalLnTemplate;
                        intervalLn.leftBound = beginValueLn;
                        intervalLn.rightBound = nextValueLn;
                        categoryName = Constants.LeftClosedInterval + beginValueLn.ToString() + Constants.SeparatorInterval + nextValueLn.ToString();
                        categoryName += (intervalLn.rightBoundType == BoundaryEnum.Sharp)? Constants.RightClosedInterval : Constants.RightOpenedInterval;

                        if (computeCategoriesNames)
                        {
                            categoriesNamesItem = new SelectString();
                            categoriesNamesItem.name = categoryName;
                            categoriesNamesItem.label = categoryName;
                            categoriesNames.Add(categoriesNamesItem);
                        }

                        categoriesStruct.longIntervals.Add(
                            categoryName,
                            new LongIntervalStruct[] { intervalLn });
                        beginValueLn = nextValueLn;
                    }

                    return new GeneratedAttribute(
                        categoriesStruct,
                        null,
                        categoriesStruct.longIntervals.Count,
                        categoriesNames.ToArray());
                default:
                    throw Ferda.Modules.Exceptions.BadParamsError(null, boxIdentity, simpleColumnType.ToString(), restrictionTypeEnum.DbColumnDataType);
            }
        }
Ejemplo n.º 35
0
 /// <summary>
 /// Gets array of <see cref="T:Ferda.Modules.SelectString"/> as list
 /// of options for <c>propertyName</c>.
 /// </summary>
 /// <param name="propertyName">Name of the property.</param>
 /// <returns>
 /// An array of <see cref="T:Ferda.Modules.SelectString"/>
 /// as list of options for property named <c>propertyName</c>.
 /// </returns>
 /// <remarks>
 /// Only for static selectboxes i.e. options doesn`t depend
 /// on box module`s inner state.
 /// </remarks>
 public SelectString[] GetPropertyFixedOptions(string propertyName)
 {
     List<SelectString> result = new List<SelectString>();
     Boxes.Serializer.Configuration.SelectOption[] selectBoxItems = this.box.GetProperty(propertyName).SelectOptions;
     if (selectBoxItems != null)
         foreach (Boxes.Serializer.Configuration.SelectOption selectBoxItem in selectBoxItems)
         {
             SelectString resultItem = new SelectString();
             resultItem.name = selectBoxItem.Name;
             result.Add(resultItem);
         }
     return result.ToArray();
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="GeneratedAttribute"/> class.
 /// </summary>
 /// <param name="categoriesStruct">The categories struct.</param>
 /// <param name="includeNullCategoryName">Name of the include null category.</param>
 /// <param name="categoriesCount">The categories count.</param>
 /// <param name="categoriesNames">The categories names.</param>
 public GeneratedAttribute(CategoriesStruct categoriesStruct, string includeNullCategoryName, long categoriesCount, SelectString[] categoriesNames)
 {
     this.categoriesStruct = categoriesStruct;
     this.categoriesCount = categoriesCount;
     this.includeNullCategoryName = includeNullCategoryName;
     this.categoriesNames = categoriesNames;
 }
 private bool? findPropertyDisabler(string propertyValue, string propertyName, SelectString[] findWhere)
 {
     foreach(SelectString selectString in findWhere)
     {
         if(selectString.name == propertyValue)
         {
             foreach (string disableProperty in selectString.disableProperties)
             {
                 if(disableProperty == propertyName) return true;
             }
             return false;
         }
     }
     return null;
 }