コード例 #1
0
        static void Main(string[] args)
        {
            BinarySerializer a = new BinarySerializer(Encoding.UTF32);

            byte[] testContents = new byte[0];
            SerializableList <double> testList = new SerializableList <double>(a, testContents, sizeof(double));

            testList.Add(1);
            testList.Add(2);
            testList.Add(3);
            testList.Add(4);
            testList.Add(5);
            testList.Add(6);
            testList.Add(7);
            var t = testList.IndexOf(5);

            testList.Insert(t, 15);
            testList.RemoveAt(2);
            t = testList.IndexOf(5);
            testList.Remove(7);
            for (int i0 = 0; i0 < testList.Count; i0++)
            {
                Console.WriteLine(testList[i0]);
            }
            Console.ReadKey();
        }
コード例 #2
0
        /// <summary>Hit when the Save button is clicked.</summary>
        /// <param name="sender">btnSave</param>
        /// <param name="e">Event Args</param>
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                //The user wanted to save. Save our settings and raise the closeform event.
                string selProjects = "";
                SerializableList <string> availProjects = new SerializableList <string>();

                foreach (Business.SpiraProject proj in this.lstAvailProjects.Items)
                {
                    availProjects.Add(Business.SpiraProject.GenerateToString(proj));
                }
                foreach (Business.SpiraProject proj in this.lstSelectProjects.Items)
                {
                    string projstr = Business.SpiraProject.GenerateToString(proj);
                    availProjects.Add(projstr);
                    selProjects += projstr + SpiraProject.CHAR_RECORD;
                }
                selProjects = selProjects.Trim(SpiraProject.CHAR_RECORD);

                //Save the selected projects to the settings.
                if (!string.IsNullOrWhiteSpace(this._solname))
                {
                    if (Settings.Default.AssignedProjects.ContainsKey(this._solname))
                    {
                        Settings.Default.AssignedProjects[this._solname] = selProjects;
                    }
                    else
                    {
                        Settings.Default.AssignedProjects.Add(this._solname, selProjects);
                    }
                }

                Settings.Default.AllProjects = availProjects;
                Settings.Default.Save();

                this.DialogResult = true;
            }
            catch (Exception ex)
            {
                Logger.LogMessage(ex, "btnSave_Click()");
                MessageBox.Show(StaticFuncs.getCultureResource.GetString("app_General_UnexpectedError"), StaticFuncs.getCultureResource.GetString("app_General_ApplicationShortName"), MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
コード例 #3
0
        public override void LoadChildren()
        {
            // Load Definitions
            var definitions = GetFeatureDefinitionIndex().Distinct(new SPFeatureDefinitionComparer());

            // Load Active Features
            Dictionary <Guid, SPFeature> featureIndex = this.FeatureCollection.ToDictionary(p => p.DefinitionId);


            // Unordered List
            var unorderedList = new SerializableList <ISPNode>();

            foreach (var def in definitions)
            {
                SPFeatureNode node = new SPFeatureNode();
                node.Definition = def;
                node.Setup(this);

                if (featureIndex.ContainsKey(def.Id))
                {
                    node.SPObject  = featureIndex[def.Id];
                    node.Activated = true;

                    featureIndex.Remove(def.Id);
                }

                unorderedList.Add(node);
            }

            foreach (var entry in featureIndex)
            {
                SPFeatureNode node = new SPFeatureNode();
                node.Definition = null;
                node.Setup(this);
                node.Text += " (Error: Missing definition)";

                unorderedList.Add(node);
            }


            // Add Inactive Features node from definitions
            this.Children = new SerializableList <ISPNode>(unorderedList.OrderBy(p => p.Text));
        }
コード例 #4
0
        public void SerializableDictionaryOfIPAddrSerialization()
        {
            XmlSerializer             serializer = new XmlSerializer(typeof(SerializableList <IPAddr>));
            MemoryStream              ms         = new MemoryStream();
            IPAddr                    outAddr    = IPAddr.Parse("192.168.1.1");
            SerializableList <IPAddr> list       = new SerializableList <IPAddr>();

            list.Add(outAddr);
            list.Add(outAddr);
            serializer.Serialize(ms, list);
            ms.Position = 0;
            SerializableList <IPAddr> inAddr = (SerializableList <IPAddr>)serializer.Deserialize(ms);

            foreach (IPAddr ip in inAddr)
            {
                Assert.AreEqual("192.168.1.1", ip.ToString());
                Assert.AreEqual("192.168.1.1", ip.ToString());
            }
        }
コード例 #5
0
        protected virtual SerializableList <ISettings> LoadChildren()
        {
            SerializableList <ISettings>   result        = new SerializableList <ISettings>();
            OrderingCollection <ISettings> importedNodes = CompositionProvider.GetOrderedExports <ISettings>(this.GetType().FullName);

            foreach (var item in importedNodes)
            {
                result.Add(item.Value);
            }

            return(result);
        }
コード例 #6
0
        private async Task <SerializableList <Guid> > UpdatePageGuidsAsync(Guid unifiedSetGuid, List <string> pageList)
        {
            pageList = pageList != null ? pageList : new List <string>();
            SerializableList <Guid> pageGuids = new SerializableList <Guid>();

            using (PageDefinitionDataProvider pageDP = new PageDefinitionDataProvider()) {
                // Get all pages that are currently part of the unified page set
                List <DataProviderFilterInfo> filters = null;
                filters = DataProviderFilterInfo.Join(filters, new DataProviderFilterInfo {
                    Field = nameof(PageDefinition.UnifiedSetGuid), Operator = "==", Value = unifiedSetGuid
                });
                DataProviderGetRecords <PageDefinition> pageDefs = await pageDP.GetItemsAsync(0, 0, null, filters);

                // translate page list to guid list (preserving order)
                foreach (string page in pageList)
                {
                    PageDefinition pageDef = await pageDP.LoadPageDefinitionAsync(page);

                    if (pageDef != null)
                    {
                        pageGuids.Add(pageDef.PageGuid);
                        // check if it's already in the list
                        PageDefinition pageFound = (from p in pageDefs.Data where p.Url == page select p).FirstOrDefault();
                        if (pageFound == null)
                        {
                            // page not in list, add it
                            pageDef.UnifiedSetGuid = unifiedSetGuid;
                            await pageDP.SavePageDefinitionAsync(pageDef);
                        }
                        else if (pageFound.UnifiedSetGuid != unifiedSetGuid)
                        {
                            // page in list but with the wrong unifiedSetGuid
                            pageDef.UnifiedSetGuid = unifiedSetGuid;
                            await pageDP.SavePageDefinitionAsync(pageDef);

                            pageDefs.Data.Remove(pageFound);
                        }
                        else
                        {
                            // page already in list
                            pageDefs.Data.Remove(pageFound);
                        }
                    }
                }
                // remove all remaining pages from unified page set, they're no longer in the list
                foreach (PageDefinition pageDef in pageDefs.Data)
                {
                    pageDef.UnifiedSetGuid = null;
                    await pageDP.SavePageDefinitionAsync(pageDef);
                }
            }
            return(pageGuids);
        }
コード例 #7
0
        public void TestSerializationDeserialization()
        {
            SerializableList <ITest> list = new SerializableList <ITest>();

            XmlSerializer xmlSerializer = new XmlSerializer(typeof(SerializableList <ITest>));
            StringBuilder xml           = new StringBuilder();

            list.Add(new Test1("str1", 4));
            list.Add(new Test1("str2", -1));
            list.Add(new Test1("str3", 0));
            xmlSerializer.Serialize(new StringWriter(xml), list);

            Console.Write(xml);

            SerializableList <ITest> list2 = (SerializableList <ITest>)xmlSerializer.Deserialize(new StringReader(xml.ToString()));

            for (int i = 0; i < list.Count; i++)
            {
                Assert.AreEqual(list[i], list2[i]);
            }
        }
コード例 #8
0
ファイル: BossBase.cs プロジェクト: iliakonnov/AdventureBot
            public static SerializableList Save(IEnumerable <Attacker> attackers)
            {
                var result = new SerializableList();

                foreach (var attacker in attackers)
                {
                    var container = new VariableContainer();
                    container.Set("damageDealed", new Serializable.Decimal(attacker.DamageDealed));
                    container.Set("userId", attacker.UserId);
                    result.Add(container);
                }

                return(result);
            }
コード例 #9
0
        // Find an action with the specified menu text
        private ModuleAction FindAction(SerializableList <ModuleAction> menuList, string menuText)
        {
            if (string.IsNullOrWhiteSpace(menuText))
            {
                return(null);
            }
            string mtext = GetFirstMenuText(ref menuText);

            foreach (ModuleAction action in menuList)
            {
                if (action.MenuText == mtext)
                {
                    if (string.IsNullOrWhiteSpace(menuText))
                    {
                        return(action);// found lowest menu matching the entire menu string menu>submenu>submenu
                    }
                    if (action.SubMenu == null || action.SubMenu.Count == 0)
                    {
                        action.SubMenu = new SerializableList <ModuleAction> {
                            new ModuleAction()
                            {
                                MenuText = mtext,
                                LinkText = mtext,
                                SubMenu  = new SerializableList <ModuleAction>(),
                            }
                        };
                    }
                    return(FindAction(action.SubMenu, menuText));
                }
            }
            ModuleAction newParent = new ModuleAction()
            {
                MenuText = mtext,
                LinkText = mtext,
                SubMenu  = new SerializableList <ModuleAction>(),
            };

            menuList.Add(newParent);
            if (string.IsNullOrWhiteSpace(menuText))
            {
                return(newParent);
            }
            else
            {
                return(FindAction(newParent.SubMenu, menuText));
            }
        }
コード例 #10
0
 public void Create()
 {
     TotalBalls = CountBalls();
     if (toCreate == null)
     {
         throw new UnassignedReferenceException("Enter a Object to create");
     }
     if ((layers * (width * width)) > 4000)
     {
         print("TO MANY BALS!!");
     }
     else
     {
         GameObject ballParent = new GameObject("Balls");
         ballParents.Add(ballParent);
         SerializableList toAdd      = new SerializableList();
         Vector3          currentPos = position;
         for (int i = 0; i < layers; i++)
         {
             for (int o = 0; o < width; o++)
             {
                 currentPos.z = position.z + o;
                 for (int p = 0; p < width; p++)
                 {
                     GameObject tmp = (GameObject)Instantiate(toCreate, currentPos, Quaternion.identity);
                     tmp.transform.parent = ballParent.transform;
                     toAdd.Add(tmp);
                     balsCreated++;
                     currentPos.z += distance;
                 }
                 currentPos.x += distance;
             }
             currentPos.y += distance;
             currentPos.x  = position.x + i;
         }
         TotalBalls += balsCreated;
         balsCreated = 0;
         balls.Add(toAdd);
         //balls.Add(ballParent);
     }
 }
コード例 #11
0
ファイル: APPConfig.cs プロジェクト: kaoken/mc2d-stage-editor
        /// <summary>
        ///
        /// </summary>
        /// <param name="filePath"></param>
        public void AddRecentProject(string filePath)
        {
            for (int i = 0; i < RecentProjects.Count; ++i)
            {
                if (RecentProjects[i].FilePath == filePath)
                {
                    RecentProjects.Remove(RecentProjects[i]);
                    break;
                }
            }
            var m = new RecentProject();
            var a = filePath.Split('\\');

            m.Title = a[0];
            string t = "";

            for (int i = a.Length - 1; i > 0; --i)
            {
                t = @"\" + a[i] + t;
                if (t.Length > 64)
                {
                    t = @"\..." + t;
                    break;
                }
            }
            m.Title   += t;
            m.FilePath = filePath;
            RecentProjects.Add(m);
            if (RecentProjects.Count > 10)
            {
                int i = RecentProjects.Count - 10;
                for (int j = 0; j < i; ++j)
                {
                    RecentProjects.Remove(RecentProjects[0]);
                }
            }
        }
コード例 #12
0
ファイル: LoginJob.cs プロジェクト: KRSogaard/UkData.Scraper
 public static SerializableList<string> GetDDFieldsList(CQ dom)
 {
     var data = new SerializableList<string>();
     foreach (var dd in dom.Select(x => x.Cq()))
     {
         var topField = dd[0].InnerText.Trim();
         if (!data.Contains(topField))
         {
             data.Add(ToolsHelper.MakeXmlSafe(topField));
         }
     }
     return data;
 }
コード例 #13
0
 public void Add(T deltaState)
 {
     deltaStates.Add(deltaState);
 }
コード例 #14
0
        private async Task ExtractPageSectionAsync(List <string> lines, bool build)
        {
            for (; lines.Count > 0;)
            {
                // get the menu path (site url)
                string urlLine = lines.First();
                if (urlLine.StartsWith("::"))
                {
                    break; // start of a new section
                }
                ++_LineCounter; lines.RemoveAt(0);
                if (urlLine.Trim() == "")
                {
                    continue;
                }
                string[] s = urlLine.Split(new char[] { ' ' }, 2);
                if (s.Length != 2)
                {
                    throw TemplateError("Url {0} invalid", urlLine);
                }

                string user = s[0].Trim();
                string url  = s[1].Trim();

                // validate url
                if (url.Length == 0 || url[0] != '/')
                {
                    throw TemplateError("Url must start with / and can't be indented");
                }

                PageDefinition page = null;
                if (build)
                {
                    page = await PageDefinition.CreatePageDefinitionAsync(url);
                }
                else
                {
                    page = await PageDefinition.LoadFromUrlAsync(url);

                    if (page != null)
                    {
                        await PageDefinition.RemovePageDefinitionAsync(page.PageGuid);
                    }
                    page = new PageDefinition();
                }
                _CurrentPage = page;
                _CurrentUrl  = url;

                while (TryPageTitle(page, lines) || TryPageDescription(page, lines))
                {
                    ;
                }

                // Get the Menu Text
                if (lines.Count < 1)
                {
                    throw TemplateError("Menu missing");
                }
                string menu = lines.First(); ++_LineCounter; lines.RemoveAt(0);
                if (string.IsNullOrWhiteSpace(menu))
                {
                    throw TemplateError("Menu missing");
                }
                if (!char.IsWhiteSpace(menu[0]))
                {
                    throw TemplateError("Menu line must be indented");
                }
                menu = menu.Trim();

                // add a menu entry to the site menu
                if (menu != "-")
                {
                    if (build)
                    {
                        ModuleAction action = await AddMenuAsync(menu);

                        //if (string.IsNullOrWhiteSpace(action.Url)) // I don't remember why this was here
                        action.Url = url;
                    }
                    else
                    {
                        await RemoveMenuAsync(menu);
                    }
                }

                // Get the skin
                if (lines.Count < 1)
                {
                    throw TemplateError("Skin missing");
                }
                string skin = lines.First(); ++_LineCounter; lines.RemoveAt(0);
                if (string.IsNullOrWhiteSpace(skin))
                {
                    throw TemplateError("Skin missing");
                }
                if (!char.IsWhiteSpace(skin[0]))
                {
                    throw TemplateError("Skin line must be indented");
                }
                skin = skin.Trim();
                if (skin == "-")
                {
                    skin = ",,,";
                }
                string[] skinparts = skin.Split(new char[] { ',' });
                if (skinparts.Length != 4)
                {
                    throw TemplateError("Invalid skin format");
                }

                page.SelectedSkin.Collection = skinparts[0].Trim();
                if (page.SelectedSkin.Collection == "-")
                {
                    page.SelectedSkin.Collection = null;
                }
                page.SelectedSkin.FileName        = skinparts[1].Trim();
                page.SelectedPopupSkin.Collection = skinparts[2].Trim();
                if (page.SelectedPopupSkin.Collection == "-")
                {
                    page.SelectedPopupSkin.Collection = null;
                }
                page.SelectedPopupSkin.FileName = skinparts[3].Trim();

                SerializableList <PageDefinition.AllowedRole> roles = new SerializableList <PageDefinition.AllowedRole>();
                switch (user)
                {
                case "Administrator":
                    roles.Add(new PageDefinition.AllowedRole {
                        RoleId = Resource.ResourceAccess.GetAdministratorRoleId(), View = PageDefinition.AllowedEnum.Yes, Edit = PageDefinition.AllowedEnum.Yes, Remove = PageDefinition.AllowedEnum.Yes,
                    });
                    break;

                case "User":
                    roles.Add(new PageDefinition.AllowedRole {
                        RoleId = Resource.ResourceAccess.GetUserRoleId(), View = PageDefinition.AllowedEnum.Yes,
                    });
                    roles.Add(new PageDefinition.AllowedRole {
                        RoleId = Resource.ResourceAccess.GetEditorRoleId(), View = PageDefinition.AllowedEnum.Yes, Edit = PageDefinition.AllowedEnum.Yes,
                    });
                    roles.Add(new PageDefinition.AllowedRole {
                        RoleId = Resource.ResourceAccess.GetAdministratorRoleId(), View = PageDefinition.AllowedEnum.Yes, Edit = PageDefinition.AllowedEnum.Yes, Remove = PageDefinition.AllowedEnum.Yes,
                    });
                    break;

                case "Anonymous":
                    roles.Add(new PageDefinition.AllowedRole {
                        RoleId = Resource.ResourceAccess.GetAnonymousRoleId(), View = PageDefinition.AllowedEnum.Yes,
                    });
                    roles.Add(new PageDefinition.AllowedRole {
                        RoleId = Resource.ResourceAccess.GetEditorRoleId(), View = PageDefinition.AllowedEnum.Yes, Edit = PageDefinition.AllowedEnum.Yes,
                    });
                    roles.Add(new PageDefinition.AllowedRole {
                        RoleId = Resource.ResourceAccess.GetAdministratorRoleId(), View = PageDefinition.AllowedEnum.Yes, Edit = PageDefinition.AllowedEnum.Yes, Remove = PageDefinition.AllowedEnum.Yes,
                    });
                    break;

                case "Anonymous+User":
                    roles.Add(new PageDefinition.AllowedRole {
                        RoleId = Resource.ResourceAccess.GetAnonymousRoleId(), View = PageDefinition.AllowedEnum.Yes,
                    });
                    roles.Add(new PageDefinition.AllowedRole {
                        RoleId = Resource.ResourceAccess.GetUserRoleId(), View = PageDefinition.AllowedEnum.Yes,
                    });
                    roles.Add(new PageDefinition.AllowedRole {
                        RoleId = Resource.ResourceAccess.GetEditorRoleId(), View = PageDefinition.AllowedEnum.Yes, Edit = PageDefinition.AllowedEnum.Yes,
                    });
                    roles.Add(new PageDefinition.AllowedRole {
                        RoleId = Resource.ResourceAccess.GetAdministratorRoleId(), View = PageDefinition.AllowedEnum.Yes, Edit = PageDefinition.AllowedEnum.Yes, Remove = PageDefinition.AllowedEnum.Yes,
                    });
                    break;

                default:
                    throw TemplateError("User {0} invalid", user);
                }
                page.AllowedRoles = roles;

                // Get zero, one or more modules (add to Main section)
                for (; lines.Count > 0;)
                {
                    string modsLine = lines.First();
                    if (string.IsNullOrWhiteSpace(modsLine))
                    {
                        ++_LineCounter; lines.RemoveAt(0);
                        continue;
                    }
                    if (!char.IsWhiteSpace(modsLine[0]))
                    {
                        break;// not a module - module lines must be indented
                    }
                    // Load assembly
                    ++_LineCounter; lines.RemoveAt(0);// accept as module line
                    string[] parts  = modsLine.Split(new char[] { ':' });
                    string   pane   = null;
                    string   modDef = null;
                    if (parts.Length == 1)
                    {
                        pane   = Globals.MainPane;
                        modDef = parts[0].Trim();
                    }
                    else if (parts.Length == 2)
                    {
                        pane = parts[0].Trim();
                        if (pane == "-")
                        {
                            pane = Globals.MainPane;
                        }
                        modDef = parts[1].Trim();
                    }
                    else
                    {
                        throw TemplateError("Invalid \"pane: module definition\"");
                    }
                    ModuleDefinition mod = await EvaluateModuleAsmTypeExpression(modDef);

                    page.AddModule(pane, mod);

                    for (; lines.Count > 0;)
                    {
                        // add variable customizations (if any)
                        string varLine = lines.First();
                        if (string.IsNullOrWhiteSpace(varLine))
                        {
                            ++_LineCounter; lines.RemoveAt(0);
                            continue;
                        }
                        // if this line is more indented than the module line, it must be a variable line
                        if (varLine.Length - varLine.TrimStart(new char[] { ' ' }).Length <= modsLine.Length - modsLine.TrimStart(new char[] { ' ' }).Length)
                        {
                            break;
                        }
                        // process variables
                        ++_LineCounter; lines.RemoveAt(0);// accept as variable line
                        if (varLine.Trim() == "")
                        {
                            continue;
                        }
                        string[] sv = varLine.Split(new char[] { '=' }, 2);
                        if (varLine.Trim().EndsWith(")"))  // method call
                        {
                            varLine = varLine.Trim();
                            if (build)
                            {
                                await InvokeMethodAsync(varLine, varLine, mod);
                            }
                        }
                        else if (sv.Length >= 2)     // variable assignment
                        {
                            if (build)
                            {
                                AssignVariable(mod, sv[0].Trim(), sv[1].Trim());
                            }
                        }
                        else
                        {
                            throw TemplateError("Variable assignment invalid");
                        }
                    }
                }
                if (build)
                {
                    await page.SaveAsync();
                }
                _CurrentPage = null;
                _CurrentUrl  = null;
            }
        }
コード例 #15
0
 public void Add(T state)
 {
     states.Add(state);
 }
コード例 #16
0
        private void btExtractDirectionInfo_Click(object sender, EventArgs e)
        {
            HtmlElement DirectionsSteps = webBrowser1.Document.GetElementById("tDirections");

            if (DirectionsSteps == null)
            {
                MessageBox.Show("oops direction is not populated yet!!");
                return;
            }
            label2.Text = "Loading... will take a while..";
            Application.DoEvents();
            SerializableList <DirectionStep> Steps = new SerializableList <DirectionStep>();
            string description   = "";
            double lat           = 0;
            double lng           = 0;
            int    PolyLineIndex = 0;

            foreach (HtmlElement InnerElement in DirectionsSteps.All)
            {
                if (InnerElement.GetAttribute("className") == "dStepDesc")
                {
                    description = InnerElement.InnerText;
                }
                if (InnerElement.GetAttribute("className") == "dLat")
                {
                    lat = double.Parse(InnerElement.InnerText);
                }
                if (InnerElement.GetAttribute("className") == "dLag")
                {
                    lng = double.Parse(InnerElement.InnerText);
                }
                if (InnerElement.GetAttribute("className") == "dPolyLineIndex")
                {
                    PolyLineIndex = int.Parse(InnerElement.InnerText);
                    DirectionStep ds = new DirectionStep(new LatLng(lat, lng), description, PolyLineIndex);
                    Steps.Add(ds);
                }
            }
            SerializableList <LatLng> Points = new SerializableList <LatLng>();
            HtmlElement PathPoints           = webBrowser1.Document.GetElementById("Points");

            if (PathPoints == null)
            {
                MessageBox.Show("oops direction is not populated yet!!");
                return;
            }

            foreach (HtmlElement InnerElement in PathPoints.All)
            {
                if (InnerElement.GetAttribute("className") == "pLat")
                {
                    lat = double.Parse(InnerElement.InnerText);
                }
                if (InnerElement.GetAttribute("className") == "pLng")
                {
                    lng = double.Parse(InnerElement.InnerText);

                    Points.Add(new LatLng(lat, lng));
                }
            }
            m_DirectionInfo = new DirectionInfo(key, Points, Steps);
            //m_DirectionInfo.
            label2.Text = "direction info loaded...";
        }
コード例 #17
0
ファイル: MysetXml.cs プロジェクト: hn20156066/GlobalHook
 public void AddMyset(List <MysetItemInfo> infos)
 {
     Mysets.Add(new MysetInfo(infos));
 }