示例#1
0
        private bool DeleteObjects <T>(LineObjectCollection <T> locLineObjects, TableSpecification ts) where T : IRemovableLineObject <T>
        {
            // DK - At the moment this method works ONLY with BIGINT type primary keys

            if (locLineObjects != null)
            {
                IdentityList il = new IdentityList();

                try
                {
                    foreach (IRemovableLineObject <T> obj in locLineObjects.Values)
                    {
                        il.AddUnique(obj.RemoveId);
                    }

                    DataCopy.ExecuteScalar(m_conn, m_transaction, "DELETE FROM {0} WHERE {1} IN ({2})", ts.TableName, ts.IdentityNames[0], il.FormatIds());

                    UpdateStatistic us = m_uss.EnsureStatistic(ts.TableName);

                    us.DeleteCount = il.Count;

                    return(true);
                }
                catch (Exception excp)
                {
                    m_logger.Excp(excp, "DeleteObjects<{0}> ERROR. ObjectIds: {1}", typeof(T), il.FormatIds());
                    throw;
                }
            }

            return(false);
        }
示例#2
0
        public void OnSceneGUI()
        {
            LineObjectCollection loc = (LineObjectCollection)target;

            for (int i = 0; i < loc.Objects.Count; i++)
            {
                if (loc.Objects[i] != null)
                {
                    UnityEditor.Handles.Label(loc.Objects[i].position, "Index: " + i.ToString("000") + "\nOffset: " + loc.GetOffsetFromObjectIndex(i).ToString("00.00"));
                }
            }
        }
示例#3
0
        private static void FindDuplucates <T>(LineObjectCollection <T> locLineObjects) where T : ILineObject <T>
        {
            Dictionary <string, T> di = new Dictionary <string, T>();

            foreach (T tObj in locLineObjects.Values)
            {
                TaggedStringLn str = tObj as TaggedStringLn;
                Debug.Assert(str != null);

                string sKey = string.Format("{0}*{1}*{2}", str.Category, str.Tag, str.Language);
                if (!di.ContainsKey(sKey))
                {
                    di.Add(sKey, tObj);
                }
                else
                {
                    m_logger.ErrorFormat("Duplicates found:\r\n{0}\r\n{1}", new Exception(), di[sKey], tObj);
                }
            }
        }
示例#4
0
        public static void lineObjectsAndStylesAccess()
        {
            Editor   ed    = AcadApp.DocumentManager.MdiActiveDocument.Editor;
            Database db    = AcadApp.DocumentManager.MdiActiveDocument.Database;
            ObjectId entId = ed.GetEntity("Pick an SLINE: ").ObjectId;

            if (entId.IsNull)
            {
                return;
            }
            Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;
            using (Transaction tr = tm.StartTransaction())
            {
                Entity entity = (Entity)tm.GetObject(entId, OpenMode.ForRead, true);

                // 2.15 Declare a LineSegment variable make it equal to the entity
                // above "entity" use "as LineSegment" for the cast
                LineSegment sline = entity as LineSegment;

                // 2.16 Use an if statement to see if the LineSegment from step 2.15
                // equals null. If it is null return.
                if (sline == null)
                {
                    return;
                }

                // 2.17 Declare a LineObjectCollection and instantiate it using the
                // GetLineObjectCollection of the LineSegment from step 2.15
                // Pass in null for the LineObjectFilter argument
                LineObjectCollection colLineObj = sline.GetLineObjectCollection(null);

                // 2.18 use a foreach statement and iterate through the LineObject
                // in the LineObjectCollection from step 2.17.
                // Note: Put the closing curly brace after step 2.28
                foreach (LineObject lo in colLineObj)
                {
                    // 2.19 Use the WriteMessage method of the editor created above "ed"
                    // use this string "\nSegment " plus the SegmentIndex property of
                    // the LineObject. (from step 2.18 in the foreach). plus this string
                    // ": " plus the GetType method of the LineObject plus this string
                    //  ", " plus the Position property of the LineObject
                    ed.WriteMessage("\nSegment " + lo.SegmentIndex +
                                    ": " + lo.GetType() + ", " + lo.Position);

                    // 2.20 The following code would list the ClassName of all Asset items
                    // on the line. Use an if statement and see if the LineObject is
                    // an InLineEntity
                    // Note: Put the closing curly brace below step 2.28
                    if (lo is InlineEntity)
                    {
                        // 2.21 The LineObject is an InLineEntity. Create a variable
                        // as an InLineEntity and make it equal to the LineObject
                        // use (InlineEntity) to cast.
                        InlineEntity loInlineEntity = (InlineEntity)lo;

                        // 2.22 Declare a variable as an entity. Instantiate it using
                        // GetObject of the transaction created above. (tm). Use the
                        // ObjectId of the InlineEntity from step 2.21. Open it for read.
                        Entity entityLo = (Entity)tm.GetObject(loInlineEntity.ObjectId, OpenMode.ForRead);

                        // 2.23 Use an if statement and see if the Entity from step 2.22 is
                        // Asset.
                        // Note: Put the closing curly brace below step 2.28
                        if (entityLo is Asset)
                        {
                            // 2.24 Declare a variable as an Asset. Instantiate it
                            // by making it equal to the Entity from step 2.22
                            // cast using (Asset)
                            Asset assetLo = (Asset)entityLo;

                            // 2.25 Use the WriteMessage method of the editor created above "ed"
                            // use this string "\nConnected to (" plus the ClassName property of
                            // the Asset from step 2.24 plus this string ")"
                            ed.WriteMessage("\nConnected to (" + assetLo.ClassName + ")");

                            // 2.26 Declare a variable as a Style. Instantiate it using
                            // GetObject of the transaction created above. (tm). Use the
                            // StyleId property of the asset (from step 2.24). Open it for read.
                            Style style = (Style)tm.GetObject(assetLo.StyleId, OpenMode.ForRead);

                            // 2.27  Create a string variable make it equal to this:
                            // "\nStyle: " plus the Name property of the Style from
                            // step 2.13  plus "\n   " repeat this pattern and use
                            // the string variable += to add the ClassName, Decription
                            // and SymbolName of the Style to the string.
                            string sMsg = "\nStyle: " + style.Name;
                            sMsg += "\n   " + style.ClassName;
                            sMsg += "\n   " + style.Description;
                            sMsg += "\n   " + style.SymbolName;


                            // 2.28 Use the WriteMessage method of the editor created
                            // above pass in the string from step 2.27
                            ed.WriteMessage(sMsg);
                        }
                    }
                }
            }
        }
示例#5
0
        public void InsertOrUpdate <T>(LineObjectCollection <T> locLineObjects, TableSpecification ts, UpdatesLn updatesLn) where T : ILineObject <T>
        {
            CheckTime ct = new CheckTime(false, "InsertOrUpdate for '{0}' entered", ts.TableName);

            List <object> lInserted = new List <object>();
            List <object> lUpdated  = new List <object>();

            m_diInserted.Add(ts.TableName, lInserted);
            m_diUpdated.Add(ts.TableName, lUpdated);

            if (locLineObjects == null)
            {
                return;
            }

            UpdateStatistic us = m_uss.EnsureStatistic(ts.TableName);

            string sInfo = string.Format("{0} table [{1}] {2};  ", m_sLiveBet, ts.TableName, locLineObjects);

#if DEBUG
            int iInsertCount = 0;
            int iUpdateCount = 0;
#endif

            try
            {
                ct.AddEvent("Empty DataTables created.");

                foreach (string sKey in locLineObjects.Keys)
                {
                    using (DataCopyTables dct = DataCopyTables.GetDataCopyTables(m_conn, m_transaction, ts.TableName))
                    {
                        T obj = locLineObjects[sKey];

                        obj.UpdateId = updatesLn.UpdateId;

                        if (obj.IsNew)
                        {
                            DataRow drNew = obj.CreateDataRow(dct.InsertDataTable);
                            dct.InsertDataTable.Rows.Add(drNew);
                            lInserted.Add(obj);
                        }
                        else
                        {
                            DataRow drNew = obj.CreateDataRow(dct.UpdateDataTable);
                            dct.UpdateDataTable.Rows.Add(drNew);
                            lUpdated.Add(obj);
                        }

#if DEBUG
                        iInsertCount = dct.InsertDataTable.Rows.Count;
                        iUpdateCount = dct.UpdateDataTable.Rows.Count;
#endif


                        if (dct.InsertDataTable.Rows.Count > 0)
                        {
                            using (IDbCommand cmdInsert = GenerateInsertCommand(m_conn, m_transaction, dct.InsertDataTable, ts))
                            {
                                using (IDisposable dsp = SqlObjectFactory.CreateDbAdapter(null) as IDisposable)
                                {
                                    IDbDataAdapter daInsert = dsp as IDbDataAdapter;
                                    Debug.Assert(daInsert != null);

                                    daInsert.InsertCommand = cmdInsert;

                                    dct.InsertDataTable.AcceptChanges();

                                    foreach (DataRow dr in dct.InsertDataTable.Rows)
                                    {
                                        dr.SetAdded();
                                    }

                                    using (DataSet ds = new DataSet())
                                    {
                                        ds.Tables.Add(dct.InsertDataTable);
                                        daInsert.Update(ds);
                                    }
                                }
                            }

                            us.InsertCount = dct.InsertDataTable.Rows.Count;
                            ct.AddEvent("Insert completed ({0})", dct.InsertDataTable.Rows.Count);
                        }

                        if (dct.UpdateDataTable.Rows.Count > 0)
                        {
                            using (IDbCommand cmdUpdate = GenerateUpdateCommand(m_conn, m_transaction, dct.UpdateDataTable, ts))
                            {
                                using (IDisposable dsp = SqlObjectFactory.CreateDbAdapter(null) as IDisposable)
                                {
                                    IDbDataAdapter daUpdate = dsp as IDbDataAdapter;
                                    Debug.Assert(daUpdate != null);

                                    daUpdate.UpdateCommand = cmdUpdate;

                                    dct.UpdateDataTable.AcceptChanges();

                                    foreach (DataRow dr in dct.UpdateDataTable.Rows)
                                    {
                                        dr.SetModified();
                                    }

                                    using (DataSet ds = new DataSet())
                                    {
                                        ds.Tables.Add(dct.UpdateDataTable);
                                        daUpdate.Update(ds);
                                    }
                                }
                            }

                            us.UpdateCount = dct.UpdateDataTable.Rows.Count;
                            ct.AddEvent("Update completed ({0})", dct.UpdateDataTable.Rows.Count);
                        }
                        ct.AddEvent("Insert/Update filled up (I.Cnt={0}; U.Cnt={1})", dct.InsertDataTable.Rows.Count, dct.UpdateDataTable.Rows.Count);
                    }
                }



                //Debug.Assert(us.Count == arrObjects.Length);

                //m_elInfo.AddFormat("{0} Result: Succeeded;  Inserted: {1};  Updated: {2};  Skipped; {3}", sInfo, us.InsertCount, us.UpdateCount, us.SkipCount);
            }
            catch (Exception excp)
            {
                m_elInfo.AddFormat("{0} Result: FAILED; Inserted: {1};  Updated: {2};", sInfo, us.InsertCount, us.UpdateCount);

#if DEBUG
                if (typeof(T) == typeof(TaggedStringLn))
                {
                    FindDuplucates(locLineObjects);
                }

                int    iCount      = 0;
                string sObjectList = string.Format("ERROR objects (Count={0})\r\n", locLineObjects.Count);

                foreach (T obj in locLineObjects.Values)
                {
                    sObjectList += obj.ToString() + "\r\n";

                    if (++iCount > MAX_ERROR_LIST_COUNT)
                    {
                        sObjectList += string.Format("And More {0} objects not listed", locLineObjects.Count - iCount);
                        break;
                    }
                }


                m_logger.Error(sObjectList, excp);
#endif
                ExcpHelper.ThrowUp(excp, "ERROR InsertOrUpdate() for {0}", locLineObjects);
            }
            finally
            {
                ct.AddEvent("InsertOrUpdate for '{0}' completed", ts.TableName);
                ct.Info(m_logger);
            }
        }