/// <summary>
        /// The function changes websites's list.
        /// <para>For example: from "toRebuild" list to the "rebuilt" list</para>
        /// </summary>
        /// <param name="newListKey">New list name where we should move the website</param>
        /// <param name="webSite">Current website to move</param>
        /// <returns>True if website was added to the new list and removed from the previous list</returns>
        public bool ChangeWebSiteList(string newListKey, WebSite webSite)
        {
            var currentListName = Lists.FirstOrDefault(kvp => kvp.Value.Any(value => value.Equals(webSite))).Key;

            var isRemoved = Lists[currentListName].Remove(webSite);

            try
            {
                if (Lists.ContainsKey(newListKey))
                {
                    Lists[newListKey].Add(webSite);
                }
                else
                {
                    try
                    {
                        if (!Lists.TryAdd(newListKey, new List <WebSite> {
                            webSite
                        }))
                        {
                            Lists[newListKey].Add(webSite);
                        }
                    }
                    catch (Exception) { }
                }
            }
            catch (Exception) { return(false); }

            return(isRemoved);
        }
        /// <summary>
        /// The function adds domain to the domains list and set it current
        /// </summary>
        /// <param name="listName">In which list we should add this domain</param>
        /// <param name="domain">Domain name</param>
        /// <param name="isInit">Needed on the application startup to increase check time</param>
        public async Task AddNew(string listName, string domain, bool isInit = false)
        {
            await Task.Run(() =>
            {
                Current = new WebSite(domain, isInit);

                if (Lists.ContainsKey(listName))
                {
                    if (!Lists[listName].Contains(Current))
                    {
                        Lists[listName].Add(Current);
                    }
                    else
                    {
                        Current = Lists[listName].Find(webSite => webSite.Equals(Current));
                    }
                }
                else
                {
                    try
                    {
                        if (!Lists.TryAdd(listName, new List <WebSite> {
                            Current
                        }))
                        {
                            Lists[listName].Add(Current);
                        }
                    }
                    catch (Exception) { }
                }

                Current.SetPreviewUrl(_server.BaseUrl.ToString());
                SetCurrentRootDirectory(Current.DomainDirectory);
            });
        }
        public static string GetVariable(string key)
        {
            if (key == "input")
            {
                return(Console.ReadLine());
            }
            string spl = key.Split(':')[0];

            if (Lists.ContainsKey(spl))
            {
                string spl1 = key.Split(':')[1];
                return(GetListIndex(spl, int.Parse(spl1)));
            }
            else if (memory.ContainsKey(key))
            {
                return(memory[key]);
            }
            else
            {
                return(key);
            }
        }
        /// <summary>
        /// The function checks if we already have some rebuilt websites
        /// </summary>
        public async Task CheckForRebuiltWebSitesAsync()
        {
            if (File.Exists(Constants.Common.WebsitesLocalBase))
            {
                await Task.Run(() => LoadList());
            }
            else
            {
                if (!Directory.Exists(Constants.Common.DomainsDir))
                {
                    return;
                }

                var key         = "rebuilt";
                var directories = await Task.Run(() => Directory.EnumerateDirectories(Constants.Common.DomainsDir).ToList());

                await Task.Run(() =>
                {
                    for (var index = 0; index < directories.Count; index++)
                    {
                        directories[index] = directories[index].Replace(Constants.Common.DomainsDir, "");
                    }

                    try { directories.ForEach(directory => AddNew(key, directory, true)); }
                    catch (Exception) { }
                });

                if (Lists.Count < 1)
                {
                    return;
                }

                if (Lists.ContainsKey(key))
                {
                    UpdateLocalBase();
                }
            }
        }
Ejemplo n.º 5
0
 private void collectionFunction()
 {
     if (POLIS[pointer].lexem == Lexem.INSERT_KW)
     {
         string objectName = Convert.ToString(stack.Pop());
         if (Lists.ContainsKey(objectName))
         {
             int    index = (int)getStackParam();
             double value = getStackParam();
             Lists[objectName].InsertAt(value, index);
         }
         else if (HTables.ContainsKey(objectName))
         {
             double value = getStackParam();
             int    key   = (int)getStackParam();
             HTables[objectName].Insert(key, value);
         }
     }
     else if (POLIS[pointer].lexem == Lexem.DISPLAY_KW)
     {
         string objectName = Convert.ToString(stack.Pop());
         if (Lists.ContainsKey(objectName))
         {
             Lists[objectName].Display();
         }
         else if (HTables.ContainsKey(objectName))
         {
             HTables[objectName].Display();
         }
     }
     else if (POLIS[pointer].lexem == Lexem.CLEAR_KW)
     {
         string objectName = Convert.ToString(stack.Pop());
         Lists[objectName].Clear();
     }
     else if (POLIS[pointer].lexem == Lexem.DELETE_AT_KW)
     {
         string objectName = Convert.ToString(stack.Pop());
         int    param      = (int)getStackParam();
         if (Lists.ContainsKey(objectName))
         {
             Lists[objectName].DeleteAt(param);
         }
         else if (HTables.ContainsKey(objectName))
         {
             HTables[objectName].Delete(param);
         }
     }
     else if (POLIS[pointer].lexem == Lexem.GET_VALUE_KW)
     {
         string objectName = Convert.ToString(stack.Pop());
         int    index      = (int)getStackParam();
         double value      = Lists[objectName].GetValue(index);
         stack.Push(value);
     }
     else if (POLIS[pointer].lexem == Lexem.GET_INDEX_KW)
     {
         string objectName = Convert.ToString(stack.Pop());
         double value      = getStackParam();
         int    index      = Lists[objectName].GetIndex(value);
         stack.Push(index);
     }
     else if (POLIS[pointer].lexem == Lexem.COUNT_KW)
     {
         string objectName = Convert.ToString(stack.Pop());
         int    size       = Lists[objectName].Count();
         stack.Push(size);
     }
     else if (POLIS[pointer].lexem == Lexem.SEARCH_KW)
     {
         string objectName = Convert.ToString(stack.Pop());
         int    key        = (int)getStackParam();
         double value      = HTables[objectName].Search(key);
         stack.Push(value);
     }
 }