コード例 #1
0
            /*------------------------------------------------------------------------------------**/
            /// <summary>
            /// IsImportFileValidFormat
            /// </summary>
            /// <param name="fileName"></param>
            /// <param name="ecClass"></param>
            /// <returns></returns>
            /*--------------+---------------+---------------+---------------+---------------+------*/
            private static bool IsImportFileValidFormat
            (
                string fileName,
                IECClass ecClass
            )
            {
                bool status           = true;
                bool assoicationFound = false;
                bool instanceFound    = false;
                int  lineNumber       = 0;

                ArrayList arr = SchemaUtilities.GetAssociatedItems(ecClass);
                bool      lookForAssociations = (arr.Count > 1);

                System.IO.StreamReader sr = System.IO.File.OpenText(fileName);

                try
                {
                    while (!sr.EndOfStream)
                    {
                        string lineRead = sr.ReadLine().Trim();
                        lineNumber++;

                        if (string.IsNullOrEmpty(lineRead))
                        {
                            continue;
                        }

                        string testString = lineRead.Replace("[Associations]", "|");
                        testString = testString.Replace("[InstanceData]", "|");
                        testString = testString.Replace("=", "|");

                        if (!testString.Contains("|"))
                        {
                            WorkspaceUtilities.DisplayErrorMessage(string.Format(LocalizableStrings.InvalidString, lineRead, lineNumber), "");
                            status = false;
                            break;
                        }

                        else if (lineRead == "[Associations]" && !lookForAssociations)
                        {
                            WorkspaceUtilities.DisplayErrorMessage(string.Format(LocalizableStrings.NoAssociationRequired, lineNumber), "");
                            status = false;
                            break;
                        }

                        else if (lineRead == "[InstanceData]" && lookForAssociations && !assoicationFound)
                        {
                            WorkspaceUtilities.DisplayErrorMessage(string.Format(LocalizableStrings.AssociationsNotDefined, ecClass.Name, lineNumber), "");
                            status = false;
                            break;
                        }

                        //Validate Associations
                        if (lineRead == "[Associations]")
                        {
                            while (!sr.EndOfStream)
                            {
                                lineRead = sr.ReadLine().Trim();
                                lineNumber++;
                                if (string.IsNullOrEmpty(lineRead))
                                {
                                    continue;
                                }

                                if (lineRead == "[InstanceData]")
                                {
                                    break;
                                }

                                string[] strs            = lineRead.Split(new char[] { '=' });
                                IECClass ecAssocateClass = SchemaUtilities.PlantSchema.GetClass(strs[0]);
                                if (ecAssocateClass == null)
                                {
                                    WorkspaceUtilities.DisplayErrorMessage(string.Format(LocalizableStrings.InvalidAssociationClass, lineNumber), "");
                                    status = false;
                                    break;
                                }
                            }
                            assoicationFound = true;
                        }

                        if (status == false)
                        {
                            break;
                        }

                        //Validate Instance Data
                        if (lineRead == "[InstanceData]")
                        {
                            while (!sr.EndOfStream)
                            {
                                lineRead = sr.ReadLine().Trim();
                                lineNumber++;
                                if (lineRead == "[InstanceData]")
                                {
                                    break;
                                }

                                if (lineRead == "[Associations]")
                                {
                                    break;
                                }

                                if (string.IsNullOrEmpty(lineRead))
                                {
                                    continue;
                                }

                                string[]    strs   = lineRead.Split(new char[] { '=' });
                                IECProperty ecProp = ecClass[strs[0]];
                                if (ecProp == null)
                                {
                                    WorkspaceUtilities.DisplayErrorMessage(string.Format(LocalizableStrings.InvalidPropertyName, lineNumber), "");
                                    status = false;
                                    break;
                                }
                            }
                            instanceFound = true;
                        }
                        if (status == false)
                        {
                            break;
                        }
                    }
                }
                finally
                {
                    sr.Close();
                }

                return(status && instanceFound);
            }
コード例 #2
0
        public bool FillAssociatedItems(bool isModifyTool)
        {
            ArrayList classRelationshipStrs = SchemaUtilities.GetAssociatedItems(_ClassDef);

            if (classRelationshipStrs.Count == 0)
            {
                return(false);
            }

            if (_bMultiInst)
            {//when editing associations of multiple instances, edit and delete options should not be available.
                this.optionDelete.Visible = false;
                this.optionEdit.Visible   = false;

                //refresh/redraw the grid
                this.OnResize(new EventArgs());
            }

            for (int i = 0; i < classRelationshipStrs.Count; i++)
            {
                string   strData = classRelationshipStrs[i] as string;
                string[] strArr  = strData.Split(new char[] { '|' });

                IECClass ecAssociatedClass           = SchemaUtilities.PlantSchema.GetClass(strArr[0]);
                int      rowIndex                    = this.Rows.Add();
                DataGridViewTextBoxCell itemTypeCell = this[s_WBSClassKey, rowIndex] as DataGridViewTextBoxCell;
                itemTypeCell.Value = ecAssociatedClass.DisplayLabel;
                //itemTypeCell.Tag = ecAssociatedClass;

                DataGridViewComboBoxCell itemInstanceCell = this[s_WBSInstanceKey, rowIndex] as DataGridViewComboBoxCell;
                //ArrayList arr = DgnUtilities.GetInstance().GetECInstanceDisplayLabelsFromDgn (strArr[0]);
                ECInstanceList       arr             = DgnUtilities.GetInstance().GetAllInstancesFromDgn(strArr[0]);
                IECRelationshipClass ecAssociatedRel = SchemaUtilities.PlantSchema.GetClass(strArr[1]) as IECRelationshipClass;
                // move class to 1st column tag, to start with,  later changed

                itemInstanceCell.Tag = ecAssociatedClass;
                itemTypeCell.Tag     = ecAssociatedRel;

                if (_bMultiInst)
                {
                    itemInstanceCell.Items.Add(_cstr_Varies);
                }

                itemInstanceCell.Items.Add(LocalizableStrings.None);

                Dictionary <string, IECInstance> dropDownCache = new Dictionary <string, IECInstance> ();

                foreach (IECInstance returnedInstance in arr)
                //for (int j = 0; j < arr.Count; j++)
                {
                    // insert only if this is not from a referenced file
                    if (DgnUtilities.GetInstance().IsECInstanceFromReferenceFile(returnedInstance))
                    {
                        continue;
                    }

                    string key = SchemaUtilities.GetDisplayNameForECInstance(returnedInstance, true);
                    if (dropDownCache.ContainsKey(key))
                    {
                        dropDownCache[key] = returnedInstance;
                    }
                    else
                    {
                        // insert
                        dropDownCache.Add(key, returnedInstance);
                        itemInstanceCell.Items.Add(key);
                    }
                }
                if (dropDownCache.Count > 0)
                {
                    itemInstanceCell.Tag = dropDownCache;
                }

                if (isModifyTool)
                {
                    string strLastInstID = null;
                    string key           = "";
                    for (int j = 0; j < _instList.Count; j++)
                    {
                        IECInstance parentInstance = GetAssociatedItemFromInstance(_instList[j], ecAssociatedRel, ecAssociatedRel.Source.GetClasses()[0].Class);
                        string      strCurrInstID  = "";

                        // If we have a parent instance, then we must be using an existing instance. We need to make sure we select the existing values.
                        if (null != parentInstance)
                        {
                            key           = SchemaUtilities.GetDisplayNameForECInstance(parentInstance, true);
                            strCurrInstID = parentInstance.InstanceId;
                        }
                        else
                        {
                            key           = LocalizableStrings.None;
                            strCurrInstID = LocalizableStrings.None;
                        }

                        if (String.IsNullOrEmpty(strLastInstID))
                        {
                            strLastInstID = strCurrInstID;
                        }
                        else
                        {
                            if (strCurrInstID != strLastInstID)
                            {
                                key = _cstr_Varies;
                                break;
                            }
                        }
                    } // end for loop

                    itemInstanceCell.Value = key;
                }

                itemInstanceCell.Sorted = true;

                DataGridViewImageCell tempImageCell = this["optionAdd", rowIndex] as DataGridViewImageCell;
                tempImageCell.Tag = ecAssociatedClass;
            }

            if (!isModifyTool)
            {
                ArrayList AssociatonList = WorkspaceUtilities.GetSettings("Associations." + _ClassDef.Name);
                LoadSettings(AssociatonList, false);
            }

            return(true);
        }