Example #1
0
        private static void Process()
        {
            var stopwatch  = new System.Diagnostics.Stopwatch();
            var index      = 1;
            var batchIndex = 1;

            for (int i = 0; i < 1000000; i++)
            {
                if (index == 1)
                {
                    stopwatch.Start();
                }

                // var key = FormsAuthentication.HashPasswordForStoringInConfigFile(SmsContent + i, "MD5");
                var key = i.ToString() + "ssss";
                if (!TreeProperty.ContainsKey(key))
                {
                    try
                    {
                        TreeProperty[key] = i;
                        TreeProperty.Commit();
                    }
                    catch (Exception ex)
                    {
                        TreeProperty.Shutdown();
                        _treeProperty = null;
                        var keyFile = Path.Combine(TreeDataDir, TreeFileName);
                        if (File.Exists(keyFile))
                        {
                            File.Delete(keyFile);
                            Console.WriteLine("Delete The Bad Key File Done!");
                        }

                        TreeProperty[key] = i;
                        TreeProperty.Commit();
                    }
                }
                else
                {
                    Console.WriteLine("ContainsKey:" + key);
                }

                index++;

                if (index == StatCount)
                {
                    stopwatch.Stop();
                    var spendSeconds = stopwatch.Elapsed.TotalSeconds;
                    var speed        = StatCount / spendSeconds;
                    Console.WriteLine(batchIndex + ".Speed:" + speed.ToString("0.00") + "/s");
                    stopwatch.Reset();
                    index = 1;
                    batchIndex++;
                }
            }

            TreeProperty.Shutdown();
            Console.WriteLine("Done!");
            Console.ReadLine();
        }
Example #2
0
 public void Remove <K>(K key)
 {
     if (key is int || key is short || key is uint || key is ushort || key is long || key is ulong)
     {
         TreeProperty.RemoveKey(key.ToString());
     }
     else
     {
         HBplusTree.RemoveKey(DataSerializer.SerializerBase64(key));
     }
 }
Example #3
0
 public ExtendTreeProperty(TreeProperty treeProperty)
 {
     base.Age                       = treeProperty.Age;
     base.CrownDiametrNs            = treeProperty.CrownDiametrNs;
     base.CrownDiametrWe            = treeProperty.CrownDiametrWe;
     base.CrownLength               = treeProperty.CrownLength;
     base.DiametrNs                 = treeProperty.DiametrNs;
     base.DiametrWe                 = treeProperty.DiametrWe;
     base.IdTaxationYearsNavigation = treeProperty.IdTaxationYearsNavigation;
     base.IdTreeNavigation          = treeProperty.IdTreeNavigation;
     Year = treeProperty.IdTaxationYearsNavigation.Year;
 }
        public ActionResult AddType(FormCollection collection)
        {
            var            dataString   = collection[0].ToString();
            DictionaryTree dt           = new DictionaryTree();
            TreeProperty   treeProperty = JsonHelper.JsonDeserialize <TreeProperty>(dataString);

            dt.dt_id     = treeProperty.id;
            dt.is_leaf   = treeProperty.type;
            dt.name      = treeProperty.name;
            dt.parent_id = treeProperty.pid;
            if (treeProperty.pid.ToString() != "11111111-1111-1111-1111-111111111111")
            {
                dt.parent_name = this.StoreService.GetTreeName(treeProperty.pid);
            }
            this.StoreService.InsertDictionaryTree(dt);
            //var list = this.StoreService.GetDictionaryTreeList(null);
            return(View());
        }
Example #5
0
        private static ICollection <Tree> GetListTree(Range range)
        {
            List <Tree> trees = new List <Tree>();
            int         raw   = 19;

            while (!((range.Cells[raw, 1] as Range).Value2 is null))
            {
                using (var context = new ConstantTrialPlotsContext())
                {
                    var tree = new Tree()
                    {
                        IdPlot  = TrialPlot.Id,
                        Number  = (int)(range.Cells[raw, 1] as Range).Value2,
                        X       = (double)(range.Cells[raw, 2] as Range).Value2,
                        Y       = (double)(range.Cells[raw, 3] as Range).Value2,
                        IdBreed = context.Breed.ToList().FirstOrDefault(e => e.Cipher == (range.Cells[raw, 4] as Range).Value2).Id,
                    };

                    context.Tree.Add(tree);
                    context.SaveChanges();
                    var property = new TreeProperty
                    {
                        Age             = (int)(range.Cells[raw, 6] as Range).Value2,
                        DiametrNs       = (double)(range.Cells[raw, 7] as Range).Value2,
                        DiametrWe       = (double)(range.Cells[raw, 9] as Range).Value2,
                        Height          = (double)(range.Cells[raw, 10] as Range).Value2,
                        CrownDiametrNs  = (range.Cells[raw, 11] as Range).Value2 as double?,
                        CrownDiametrWe  = (range.Cells[raw, 12] as Range).Value2 as double?,
                        CrownLength     = (range.Cells[raw, 14] as Range).Value2 as double?,
                        IdCraft         = context.СraftСategory.ToList().FirstOrDefault(c => c.Chipher == ArabToRim((int?)(range.Cells[raw, 15] as Range).Value2)).Id,
                        IdSuitability   = context.TechnicalSuitability.ToList().FirstOrDefault(t => t.Chipher == (string)(range.Cells[raw, 16] as Range).Value2).Id,
                        IdTaxationYears = TaxationYear.Id,
                        IdTree          = tree.Id
                    };

                    context.TreeProperty.Add(property);
                    context.SaveChanges();
                }
                raw++;
            }
            return(trees);
        }
Example #6
0
 set => SetValue(TreeProperty, value);
        private void PopulateTreeTest()
        {
            this.Tree.Items.Clear();
            TreeProperty root = new TreeProperty("root", "Template", "Template");

            TreeProperty c1 = new TreeProperty("c1", "Concept1", "Concept");
            c1.Items.Add(new TreeProperty("cl1", "Clause1", "Clause"));
            c1.Items.Add(new TreeProperty("cl2", "Clause2", "Clause"));
            c1.Items.Add(new TreeProperty("cl3", "Clause3", "Clause"));
            root.Items.Add(c1);

            TreeProperty c2 = new TreeProperty("c2", "Concept2", "Concept");
            c2.Items.Add(new TreeProperty("cl1", "Clause1", "Clause"));
            c2.Items.Add(new TreeProperty("cl2", "Clause2", "Clause"));
            c2.Items.Add(new TreeProperty("cl3", "Clause3", "Clause"));
            root.Items.Add(c2);

            this.Tree.Items.Add(root);
        }
        public void TreeSelect(TreeProperty tree, string id, string proptype)
        {
            // Check root
            if (tree.Type == proptype && (tree.Id == id))
            {
                tree.IsSelected = true;
                return;
            }

            //Step through the tree and select the matching node
            foreach (TreeProperty item in tree.Items)
            {
                if (item.Type == proptype && (item.Id == id))
                {
                    item.IsSelected = true;
                    return;
                }
                else
                {
                    if (item.Items.Count > 0)
                    {
                        this.TreeSelect((TreeProperty)item, id, proptype);
                    }
                }
            }
        }
        public void PopulateTree()
        {
            Globals.ThisAddIn.ProcessingUpdate("Populate Tree");

            try
            {

                this.Tree.Items.Clear();
                if (this.Id == null) this.Id = Globals.ThisAddIn.GetCurrentDocId();
                string name = "";
                string xml = "";

                if (this.Id != "")
                {

                    string doctype = "";
                    if (Globals.ThisAddIn.isTemplate(this.Doc))
                    {
                        this.IsTemplate = true;
                        doctype = "Template";

                        this.GetTemplateDetails();
                        if (this.DTTemplate.Rows.Count > 0)
                        {
                            name = this.DTTemplate.Rows[0]["Name"].ToString();
                        }
                        else
                        {
                            MessageBox.Show("Sorry - can't find the Template");
                            return;
                        }

                        //Show the Template and The Template Clause tabs
                        this.tabItemTemplate.Visibility = System.Windows.Visibility.Visible;
                        this.tabItemTemplate.IsSelected = true;
                        this.tabItemTClause.Visibility = System.Windows.Visibility.Visible;

                        //Hide the Clause tab
                        this.tabItemClause.Visibility = System.Windows.Visibility.Collapsed;

                        //Hide the Element Add and Element Delete buttons
                        this.btnElementAdd.Visibility = System.Windows.Visibility.Hidden;
                        this.btnElementDelete.Visibility = System.Windows.Visibility.Hidden;

                        //Populate the Template Properties
                        if (this.DTTemplate.DefaultView.Count > 0)
                        {
                            Utility.UpdateForm(new Grid[] { formGridTemplate }, ((DataRowView)this.DTTemplate.DefaultView[0]).Row);
                            Utility.ReadOnlyForm(false, new Grid[] { formGridTemplate });
                            this.btnSave.IsEnabled = false;
                            this.btnCancel.IsEnabled = false;
                        }
                    }
                    else
                    {
                        this.IsTemplate = false;
                        doctype = "Clause";
                        this.CurrentClauseId = this.Id;
                        this.GetClauseDetails();

                        if (this.DTClause.Rows.Count > 0)
                        {
                            name = this.DTClause.Rows[0]["Name"].ToString();
                        }
                        else
                        {
                            MessageBox.Show("Sorry - can't find the Clause");
                            return;
                        }

                        this.CurrentConceptId = this.DTClause.Rows[0]["Concept__r_Id"].ToString();

                        //Hide the Template Tab
                        this.tabItemTemplate.Visibility = System.Windows.Visibility.Collapsed;
                        this.tabItemTClause.Visibility = System.Windows.Visibility.Collapsed;

                        //Show the Clause tab
                        this.tabItemClause.Visibility = System.Windows.Visibility.Visible;
                        this.tabItemClause.IsSelected = true;

                        //Show the Element Add and Element Delete buttons
                        this.btnElementAdd.Visibility = System.Windows.Visibility.Visible;
                        this.btnElementDelete.Visibility = System.Windows.Visibility.Visible;

                        //Populate the Clause Properties
                        Utility.UpdateForm(new Grid[] { formGridClause }, ((DataRowView)this.DTClause.DefaultView[0]).Row);
                        Utility.ReadOnlyForm(false, new Grid[] { formGridClause });
                        btnSave.IsEnabled = false;
                        btnCancel.IsEnabled = false;

                    }

                    TreeProperty treeContract = new TreeProperty(this.Id, name, doctype);
                    TreeProperty treeItem = null;

                    if (this.IsTemplate)
                    {
                        // Get the concepts from the document so the order is correct

                        Globals.ThisAddIn.ProcessingUpdate("Get Concept Order");
                        string conceptorder = Globals.ThisAddIn.GetConceptOrder(this.Doc);

                        // Get all the clauses
                        xml = "";
                        this.GetAllClauses();

                        // Generate a list of the ClauseIds so we can get all the elemets at once short term solution to cut down on the API calls
                        // [written after - wonder what the long term solution was!]

                        // TODO - build some clean up in here if the concept doesn't appear in the doc we should delete it from the database

                        List<string> clauseids = new List<string>();
                        foreach (DataRow r in this.DTClause.Rows)
                        {
                            if (!clauseids.Contains(r["Clause__r_Id"].ToString())) clauseids.Add(r["Clause__r_Id"].ToString());
                        }
                        string clausefilter = "";
                        foreach (string c in clauseids)
                        {
                            if (clausefilter == "")
                            {
                                clausefilter = "('" + c + "'";
                            }
                            else
                            {
                                clausefilter += ",'" + c + "'";
                            }
                        }
                        if (clausefilter != "") clausefilter += ")";

                        //Get all the elements
                        this.GetAllElements(clausefilter);

                        //Step through in the right order and display tree
                        if (conceptorder != "")
                        {
                            string[] cotags = conceptorder.Split(',');

                            foreach (string cotag in cotags)
                            {

                                string[] conceptdetails = cotag.Split('|');

                                // format is Concept|ConceptId|ClauseId|LastModified - last 2 may not be there
                                string concept = conceptdetails[1];

                                //Populate all the Concepts and Clauses
                                DataView dv = new DataView(this.DTClause);
                                dv.RowFilter = "Clause__r_Concept__r_Id='" + concept + "'";
                                dv.Sort = "Order__c";

                                string conceptname = "";
                                string conceptid = "";
                                if (dv.Count > 0)
                                {
                                    conceptname = dv[0]["Clause__r_Concept__r_Name"].ToString();
                                    conceptid = dv[0]["Clause__r_Concept__r_Id"].ToString();

                                    treeItem = new TreeProperty(conceptid, conceptname, "Concept");
                                }
                                else
                                {
                                    //Concept must have been removed.
                                    Globals.ThisAddIn.RemoveConcept(this.Doc, concept);
                                }

                                foreach (DataRowView r in dv)
                                {
                                    if (Convert.ToString(r["Clause__r_Concept__r_Id"]) != conceptid)
                                    {
                                        //Push the old one
                                        treeContract.Items.Add(treeItem);

                                        //Create the new one
                                        conceptid = Convert.ToString(r["Clause__r_Concept__r_Id"]);
                                        conceptname = r["Clause__r_Concept__r_Name"].ToString();
                                        treeItem = new TreeProperty(conceptid, conceptname, "Concept");
                                    }

                                    // Get the XML for this clause
                                    // ok trying to do this IF the clause in the template matches the clause
                                    // then just use the XML in the content control so we don't have to go get it

                                    // TODO this does as intended but still has to hit the db if the clause isn't the one selected
                                    // can we stash the xml of the other choices in a hidden bit of the doc?

                                    string clauseid = Convert.ToString(r["Clause__r_Id"]);
                                    string lastmodified = Convert.ToString(r["Clause__r_LastModifiedDate"]);
                                    lastmodified = lastmodified.Substring(0, 16);

                                    xml = "";
                                    bool selectedclause = false;
                                    if (conceptorder != "")
                                    {
                                        cotags = conceptorder.Split(',');
                                        foreach (string cotag1 in cotags)
                                        {
                                            conceptdetails = cotag1.Split('|');
                                            if (conceptdetails.Length > 3)
                                            {
                                                // add a special case for Import - if the tag says 4 zeros then its the uptodate version
                                                if (conceptdetails[2] == clauseid && (lastmodified == conceptdetails[3] || conceptdetails[3] == "0000"))
                                                {
                                                    selectedclause = true;
                                                }
                                            }
                                        }
                                    }

                                    // take the answer from the database if the selection and lastchanged match and we aren't being told to
                                    // (refresh button sets the ForceRefresh flag)
                                    if (selectedclause && (!this.ForceRereshClauseXML))
                                    {
                                        Globals.ThisAddIn.ProcessingUpdate("Take XML from Doc");
                                        // get the xml from the doc
                                        xml = Globals.ThisAddIn.GetTemplateClauseXML(this.Doc, conceptid);
                                        this.AddClauseXML(clauseid, xml);

                                    }

                                    if (xml == "")
                                    {
                                        Globals.ThisAddIn.ProcessingUpdate("Get the Clause Template File from SF for:" + r["Clause__r_Name"].ToString());
                                        xml = this.GetClauseXML(clauseid);
                                    }

                                    // ---------------------

                                    // Globals.ThisAddIn.ProcessingUpdate("Get the Clause Template File from SF for:" + r["Clause__r_Name"].ToString());
                                    // xml = this.GetClauseXML(clauseid);

                                    TreeProperty tpClause = new TreeProperty(Convert.ToString(r["Clause__r_Id"]), r["Clause__r_Name"].ToString(), "Clause");

                                    //Add in the elements for this clause - filter the full list for this clause
                                    DataRow[] elements = this.DTElement.Select("Clause__r_Id='" + Convert.ToString(r["Clause__r_Id"]) + "'");

                                    if (elements.Length > 0)
                                    {
                                        Globals.ThisAddIn.ProcessingUpdate("Get the Elements for:" + r["Clause__r_Name"].ToString());
                                        foreach (DataRow er in elements)
                                        {
                                            tpClause.Items.Add(new TreeProperty(Convert.ToString(er["Element__r_Id"]), er["Element__r_Name"].ToString(), "Element"));
                                        }
                                    }

                                    treeItem.Items.Add(tpClause);
                                }

                                if (dv.Count > 0) treeContract.Items.Add(treeItem);
                            }
                        }
                    }
                    else
                    {
                        this.GetElements(this.Id);
                        //Add in the elements for this clause

                        if (this.DTElement.Rows.Count > 0)
                        {
                            foreach (DataRow er in this.DTElement.Rows)
                            {
                                treeContract.Items.Add(new TreeProperty(Convert.ToString(er["Element__r_Id"]), er["Element__r_Name"].ToString(), "Element"));
                            }
                        }

                    }

                    this.Tree.ExpandAll();
                    this.Tree.Items.Add(treeContract);

                    // if this is a clause then select the clause node
                    if (!this.IsTemplate)
                    {
                        this.SelectClause(this.Id);
                    }

                }
            }
            catch (Exception e)
            {
                string errormessage = "Sorry there has been an error - " + e.Message;
                if (e.InnerException != null) errormessage += " " + e.InnerException.Message;

                MessageBox.Show(errormessage);
                // Globals.ThisAddIn.ProcessingStop("Finished");
            }
        }