コード例 #1
0
        private List <Patch> Patch(Pixel c2p)
        {
            Assem assem = null;

            try
            {
                // 计算瓦片行列
                assem = this.Bound(c2p);
            }
            catch
            {
                return(null);
            }
            // 生成瓦片集合
            List <Patch> patchs = new List <Patch>();

            for (int i = assem.MinR; i <= assem.MaxR; i++)
            {
                for (int j = assem.MinC; j <= assem.MaxC; j++)
                {
                    patchs.Add(new Patch(this.Level + i + this.Index + j, this.Level, i, j));
                }
            }
            return(patchs.OrderBy(x => this.upset.Next()).ToList());
        }
コード例 #2
0
        private static void CacheCallouts()
        {
            foreach (var Assem in Functions.GetAllUserPlugins())
            {
                var AssemName     = Assem.GetName();
                var AssemCallouts = (from Callout in Assem.GetTypes()
                                     where Callout.IsClass && Callout.BaseType == typeof(LSPD_First_Response.Mod.Callouts.Callout)
                                     select Callout).ToList();

                if (AssemCallouts.Count() < 1)
                {
                    Logger.Log(Assem.GetName().Name + " No callouts detected.");
                }

                else
                {
                    var AddCount = 0;
                    foreach (Type Callout in AssemCallouts)
                    {
                        var CalloutAttributes = Callout.GetCustomAttributes(typeof(CalloutInfoAttribute), true);

                        if (CalloutAttributes.Count() > 0)
                        {
                            var CalloutAttribute = (CalloutInfoAttribute)(from a in CalloutAttributes select a).FirstOrDefault();

                            if (CalloutAttribute != null)
                            {
                                if (Globals.Config.CalloutProbability == false)
                                {
                                    RandomCalloutCache.Add(CalloutAttribute.Name);
                                }

                                else
                                {
                                    for (var LoopCount = 0; LoopCount < CalloutProbabilityRegistrationCount[(int)CalloutAttribute.CalloutProbability] * Globals.Config.CalloutProbabilityModifier; LoopCount++)
                                    {
                                        RandomCalloutCache.Add(CalloutAttribute.Name);
                                    }
                                }
                                AddCount++;
                            }
                        }
                    }

                    Logger.Log(Assem.GetName().Name + $" detected {AddCount} callouts and added them to the ForceACallout cache.");
                }
            }

            if (Globals.Config.CalloutProbability == true)
            {
                Logger.Log($"{RandomCalloutCache.Count} total probabilities registered in ForceACallout.");
            }
        }
コード例 #3
0
        public void UpConstraints(Session nxSession, string AssemblyPart, string[] Constraints, List <ConstData> ConstInfo)
        {
            Assem = nxSession.Parts.OpenDisplay(AssemblyPart, out partloadstatus);
            componentPositioners = new ComponentPositioner[ConstInfo.Count];
            for (int i = 0; i < ConstInfo.Count; i++)
            {
                componentPositioners[i] = Assem.ComponentAssembly.Positioner;

                if (ConstInfo[i].ConstType == "Touch")
                {
                    var touchConst = new touchCons();
                    touchConst.ApplyTouch(Assem, componentPositioners[i], ConstInfo[i]);
                    //Call
                }
                else if (ConstInfo[i].ConstType == "Fit")
                {
                    var fitConst = new fitCons();
                    fitConst.ApplyFit(Assem, componentPositioners[i], ConstInfo[i]);
                }
                else if (ConstInfo[i].ConstType == "Fix")
                {
                    var fixConst = new fixCons();
                    fixConst.ApplyFix(Assem, componentPositioners[i], ConstInfo[i]);
                }
                else if (ConstInfo[i].ConstType == "Angle")
                {
                    var angConst = new angCons();
                    angConst.ApplyAng(Assem, componentPositioners[i], ConstInfo[i]);
                }
                else if (ConstInfo[i].ConstType == "Distance")
                {
                    var disConst = new disCons();
                    disConst.ApplyDis(Assem, componentPositioners[i], ConstInfo[i]);
                }
            }
            NXOpen.PartSaveStatus partSaveStatus1;
            partSaveStatus1 = Assem.Save(NXOpen.BasePart.SaveComponents.True, NXOpen.BasePart.CloseAfterSave.False);
            partSaveStatus1.Dispose();
            NXOpen.PartCloseResponses partCloseResponse1;
            partCloseResponse1 = nxSession.Parts.NewPartCloseResponses();
            Assem.Close(BasePart.CloseWholeTree.False, NXOpen.BasePart.CloseModified.UseResponses, partCloseResponse1);
            partloadstatus.Dispose();
        }
コード例 #4
0
 static Cmn()
 {
     Assem    = Assembly.GetExecutingAssembly();
     AppPath  = Assem.Location;
     AppVer   = Assem.GetName().Version;
     CurDir   = Environment.CurrentDirectory;
     PCName   = Environment.MachineName;
     UserName = Environment.UserName;
     HostName = Dns.GetHostName();
     Proc     = Process.GetCurrentProcess();
     ProcName = Proc.ProcessName;
     ProcId   = Proc.Id;
     IPAddress[] ipas = Dns.GetHostAddresses(HostName);
     foreach (IPAddress ipa in ipas)
     {
         if (ipa.AddressFamily == AddressFamily.InterNetwork)
         {
             IPv4 = ipa;
         }
         if (ipa.AddressFamily == AddressFamily.InterNetworkV6)
         {
             IPv6 = ipa;
         }
     }
     NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
     foreach (NetworkInterface adapter in adapters)
     {
         // ネットワーク接続状態が UP のアダプタのみ
         if (adapter.OperationalStatus == OperationalStatus.Up &&
             adapter.NetworkInterfaceType != NetworkInterfaceType.Loopback &&
             adapter.NetworkInterfaceType != NetworkInterfaceType.Tunnel &&
             adapter.NetworkInterfaceType != NetworkInterfaceType.Unknown
             )
         {
             // 物理(MAC)アドレスの取得
             MacAddr = adapter.GetPhysicalAddress();
             break;
         }
     }
     Refresh();
 }
コード例 #5
0
        internal static void CacheCallouts()
        {
            foreach (Assembly Assem in Functions.GetAllUserPlugins())
            {
                AssemblyName AssemName     = Assem.GetName();
                List <Type>  AssemCallouts = (from Callout in Assem.GetTypes()
                                              where Callout.IsClass && Callout.BaseType == typeof(LSPD_First_Response.Mod.Callouts.Callout)
                                              select Callout).ToList();

                if (AssemCallouts.Count() < 1)
                {
                    Logger.Log(Assem.FullName + "No callouts detected.");
                }

                else
                {
                    int AddCount = 0;
                    foreach (Type Callout in AssemCallouts)
                    {
                        object[] CalloutAttributes = Callout.GetCustomAttributes(typeof(CalloutInfoAttribute), true);

                        if (CalloutAttributes.Count() > 0)
                        {
                            CalloutInfoAttribute CalloutAttribute = (CalloutInfoAttribute)(from a in CalloutAttributes select a).FirstOrDefault();

                            if (CalloutAttribute != null)
                            {
                                RandomCalloutCache.Add(CalloutAttribute.Name);
                                AddCount++;
                            }
                        }
                    }

                    Logger.Log(Assem.FullName + $" detected {AddCount} callouts and added them to the ForceACallout cache.");
                }
            }
        }
コード例 #6
0
        private void EnumImportersFromDirectory(string importerDirectory)
        {
            if (!Directory.Exists(importerDirectory))
            {
                return;
            }
            string[] Files = Directory.GetFiles(importerDirectory, "*.DLL");

            List <string> OrderedFiles = OrderedImporterFiles(Files);

            foreach (string file in OrderedFiles)
            {
                //we know this is a native image
                MainForm.LogMessage("detecting importer file " + file + " version and creation date " + FileVersions(file));

                if (Path.GetFileName(file).ToUpper() == "BulkLoad.dll".ToUpper())
                {
                    MainForm.LogMessage(String.Format(Properties.Resources.Msg_NativeImage, file));
                    continue;
                }
                Assembly Assem;
                try
                {
                    Assem = Assembly.LoadFile(file);
                }
                catch (Exception ex)
                {
                    MainForm.LogMessage("Assembly " + file + " could not be used as an importer: " + ex.Message, MessageOptions.Silent);
                    continue;
                }

                Type[] typs = Assem.GetExportedTypes();
                foreach (Type typ in typs)
                {
                    //Ignore abstract classes
                    if (typ.IsAbstract)
                    {
                        continue;
                    }

                    //Ignore non-classes
                    if (!typ.IsClass)
                    {
                        continue;
                    }

                    TypeFilter loadIfcFilt = new TypeFilter(loadIfcFilter);
                    Type[]     ifcs        = typ.FindInterfaces(loadIfcFilt, "NexusInterfaces.INexusImporter");
                    foreach (Type ifc in ifcs)
                    {
                        //If we get in here, the Class implements the interface, so add it to the list
                        //and bail
                        INexusImporter prod = (INexusImporter)Assem.CreateInstance(typ.FullName, true);

                        prod.StatusChanged += new System.EventHandler(this.ImportStatusChanged);
                        if (prod is INexusProgressReporter)
                        {
                            (prod as INexusProgressReporter).ProgressChanged += new System.EventHandler(this.ImportProgressChanged);
                        }

                        ToolStripMenuItem tsi = new ToolStripMenuItem(prod.Name);
                        tsi.Tag = prod;
                        tsiImporters.DropDownItems.Add(tsi);

                        // Add subitems

                        // Enabled item
                        // All importers require an "Enabled" menu option -- if this doesn't exist in the options collection, add it.
                        object enabledoption;
                        if (!prod.Options.TryGetValue("Enabled", out enabledoption))
                        {
                            prod.Options.Add("Enabled", true);
                        }

                        // options
                        ToolStripMenuItem subtsi;
                        foreach (string option in prod.Options.Keys)
                        {
                            subtsi = new ToolStripMenuItem(option);
                            if (option.Substring(option.Length - 3) == "...") // dialog
                            {
                                subtsi.Tag    = prod.OptionsDialog;
                                subtsi.Click += new System.EventHandler(this.tsiDialog_Click);
                            }
                            else // boolean
                            {
                                m_OptionList.Add(subtsi);

                                subtsi.Tag          = prod;
                                subtsi.CheckOnClick = true;

                                bool UserSaved = ImportOptions.IsEnabled(String.Format("{0}.{1}", prod.Name, subtsi.Text));
                                MainForm.LogMessage("load: " + String.Format("{0}.{1}", prod.Name, option), MessageOptions.Silent);

                                if (ImportOptions.IsEnabled("SaveImportOptions"))
                                {
                                    subtsi.Checked = UserSaved;
                                }
                                else
                                {
                                    subtsi.Checked = (bool)prod.Options[option];
                                }

                                subtsi.Click += new System.EventHandler(this.tsiBool_Click);
                            }

                            tsi.DropDownItems.Add(subtsi);
                        }
                    }
                }
            }
        }
コード例 #7
0
        /// <summary>
        /// 把DataGrid中的数据按行赋给业务对象
        /// </summary>
        /// <param name="grid">DataGrid实例</param>
        /// <param name="model">业务对象的类型</param>
        /// <param name="isThrow">是否抛出异常</param>
        /// <returns>业务对象的集合</returns>
        public static List <object> BindModelByDataGrid(DataGrid grid, System.Type model, bool isThrow)
        {
            int           RowsCount = -1;
            List <object> list;
            Assembly      Assem;

            RowsCount = grid.Items.Count;
            //动态创建业务对象集合。

            try
            {
                Assem = Assembly.Load(model.Assembly.FullName);
                list  = new List <object>();
                for (int i = 0; i < RowsCount; i++)
                {
                    list.Add(Assem.CreateInstance(model.FullName, true));
                }
            }
            catch
            {
                return(null);
            }
            //获取业务类公共实例属性

            PropertyInfo[] Properties = model.GetProperties(BindingFlags.Instance |
                                                            BindingFlags.Public);

            #region 遍历每一列赋值

            for (int i = 0; i < grid.Columns.Count; i++)
            {
                if (grid.Columns[i] is BoundColumn)
                {
                    BoundColumn BC = grid.Columns[i] as BoundColumn;
                    foreach (PropertyInfo Property in Properties)
                    {
                        if (Property.Name == BC.DataField)
                        {
                            //把该列的每一行赋值给业务对象
                            for (int j = 0; j < RowsCount; j++)
                            {
                                try
                                {
                                    if (grid.Items[j].Cells[i].HasControls())
                                    {
                                        Property.SetValue(list[j],
                                                          Convert.ChangeType((grid.Items[j].Cells[i].Controls[0] as TextBox).Text, Property.PropertyType),
                                                          null);
                                    }
                                    else
                                    {
                                        Property.SetValue(list[j], Convert.ChangeType(grid.Items[j].Cells[i].Text, Property.PropertyType), null);
                                    }
                                }
                                catch
                                {
                                    if (isThrow)
                                    {
                                        throw;
                                    }
                                    else
                                    {
                                        continue;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            #endregion 遍历每一列赋值



            return(list);
        }