public void ProcessClientTlb(string ProgId, string SrcTlbPath, string PhysicalPath, string VRoot, string BaseUrl, string Mode, string Transport, out string AssemblyName, out string TypeName, out string Error)
 {
     AssemblyName = "";
     TypeName     = "";
     Error        = "";
     try
     {
         new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand();
         string clientPhysicalPath = GetClientPhysicalPath(true);
         if (!SrcTlbPath.ToLower(CultureInfo.InvariantCulture).EndsWith("mscoree.dll", StringComparison.Ordinal) && (SrcTlbPath.Length > 0))
         {
             AssemblyName = new GenerateMetadata().Generate(SrcTlbPath, clientPhysicalPath);
             if (ProgId.Length > 0)
             {
                 TypeName = this.GetTypeNameFromProgId(clientPhysicalPath + AssemblyName + ".dll", ProgId);
             }
         }
         else if (ProgId.Length > 0)
         {
             string      g    = (string)Registry.ClassesRoot.OpenSubKey(ProgId + @"\CLSID").GetValue("");
             RegistryKey key2 = Registry.ClassesRoot.OpenSubKey(@"CLSID\{" + new Guid(g) + @"}\InprocServer32");
             AssemblyName = (string)key2.GetValue("Assembly");
             int index = AssemblyName.IndexOf(",");
             if (index > 0)
             {
                 AssemblyName = AssemblyName.Substring(0, index);
             }
             TypeName = (string)key2.GetValue("Class");
         }
         if (ProgId.Length > 0)
         {
             Uri baseUri = new Uri(BaseUrl);
             Uri uri2    = new Uri(baseUri, VRoot);
             if (uri2.Scheme.ToLower(CultureInfo.InvariantCulture) == "https")
             {
                 string authentication = "Windows";
                 SoapClientConfig.Write(clientPhysicalPath, uri2.AbsoluteUri, AssemblyName, TypeName, ProgId, authentication);
             }
             else
             {
                 ClientRemotingConfig.Write(clientPhysicalPath, VRoot, BaseUrl, AssemblyName, TypeName, ProgId, Mode, Transport);
             }
         }
     }
     catch (Exception exception)
     {
         if ((exception is NullReferenceException) || (exception is SEHException))
         {
             throw;
         }
         Error = exception.ToString();
         ComSoapPublishError.Report(Error);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Событие возникет когда при загрузке ClientApp JIT не может найти сборку из References.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args">Ненайденная сборка</param>
        /// <returns>Сборка</returns>
        private static Assembly OnAssemblyResolve(object sender, ResolveEventArgs args)
        {
            string name = new AssemblyName(args.Name).Name;

            //name = name.Replace(".resources", "");
            //поиск загруженной сборки.
            if (name.IndexOf(".resources", System.StringComparison.OrdinalIgnoreCase) > 0)
            {
                return(null);
            }
            foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                if (assembly.GetName().Name == name)
                {
                    return(assembly);
                }
            }

            string PathMain = System.Windows.Forms.Application.StartupPath + "\\";
            string PathDll  = Path.GetDirectoryName(Path.GetDirectoryName(PathMain)) + @"\" + name + ".dll";

            if (!File.Exists(PathDll))
            {
                MessageBox.Show("Не найден файл: " + name, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(null);
            }
            try
            {
                //return Assembly.LoadFile(PathDll);
                using (Stream io = Assembly.GetExecutingAssembly().GetManifestResourceStream(name))
                {
                    if (io == null)
                    {
                        //MessageBox.Show("Ошибка при загрузке файла DLL: " + name,  "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        Environment.Exit(-1);
                    }
                    using (var binaryReader = new BinaryReader(io))
                    {
                        return(Assembly.Load(binaryReader.ReadBytes((int)io.Length)));
                    }
                }
            } catch (Exception ex)
            {
                MessageBox.Show("Ошибка при загрузке файла DLL: " + name + " " + ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(null);
            }
        }
Exemplo n.º 3
0
        public JObject makeVersionJson(CswSessionResourcesNbt _CswSessionResources)
        {
            JObject ret = new JObject();

            string AssemblyFilePath = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath + "/_Assembly.txt";

            if (File.Exists(AssemblyFilePath))
            {
                TextReader AssemblyFileReader = new StreamReader(AssemblyFilePath);
                ret.Add(new JProperty("assembly", AssemblyFileReader.ReadLine()));
                AssemblyFileReader.Close();
            }

            JObject   ComponentObj   = new JObject();
            JProperty ComponentsProp = new JProperty("components", ComponentObj);

            ret.Add(ComponentsProp);
            string ThisYear = DateTime.Now.Year.ToString();

            ArrayList CswAssemblies = new ArrayList();

            CswAssemblies.Add("NbtWebApp");
            CswAssemblies.Add("CswCommon");
            CswAssemblies.Add("CswWebControls");
            CswAssemblies.Add("NbtLogic");
            CswAssemblies.Add("NbtWebControls");

            foreach (string AssemblyName in CswAssemblies)
            {
                string name = AssemblyName.Contains(",") ? AssemblyName.Substring(0, AssemblyName.IndexOf(',')) : AssemblyName;

                JObject AssemObj = new JObject();
                ComponentObj.Add(new JProperty(name, AssemObj));

                Assembly AssemblyInfo = Assembly.Load(AssemblyName);
                string   Version      = AssemblyInfo.GetName().Version.ToString();
                AssemObj.Add(new JProperty("name", name));
                AssemObj.Add(new JProperty("version", Version));
                AssemObj.Add(new JProperty("copyright", "Copyright &copy; ChemSW, Inc. 2005-" + ThisYear));
            }

            ArrayList ThirdAssemblies = new ArrayList();

            ThirdAssemblies.Add("CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304");
            ThirdAssemblies.Add("Telerik.Web.UI");

            foreach (string AssemblyName in ThirdAssemblies)
            {
                string name = AssemblyName.Contains(",") ? AssemblyName.Substring(0, AssemblyName.IndexOf(',')) : AssemblyName;

                JObject AssemObj = new JObject();
                ComponentObj.Add(new JProperty(name, AssemObj));

                Assembly AssemblyInfo       = Assembly.Load(AssemblyName);
                object[] AssemblyAttributes = (object[])AssemblyInfo.GetCustomAttributes(true);

                string Version   = AssemblyInfo.GetName().Version.ToString();
                string Copyright = string.Empty;
                foreach (AssemblyCopyrightAttribute AssemblyAttribute in AssemblyAttributes.OfType <AssemblyCopyrightAttribute>())
                {
                    Copyright = (AssemblyAttribute).Copyright;
                }
                AssemObj.Add(new JProperty("name", name));
                AssemObj.Add(new JProperty("version", Version));
                AssemObj.Add(new JProperty("copyright", Copyright));
            }

            ComponentObj.Add(new JProperty("Schema",
                                           new JObject(
                                               new JProperty("name", "Schema"),
                                               new JProperty("version", _CswNbtResources.ConfigVbls.getConfigVariableValue("schemaversion")),
                                               new JProperty("copyright", "Copyright &copy; ChemSW, Inc. 2005-" + ThisYear)
                                               )

                                           ));

            #region ChemCatCentral Products Versions
            // Add ChemCatCentral version to the About dialog: Case 29380
            if (_CswNbtResources.Modules.IsModuleEnabled(CswEnumNbtModuleName.C3Products))
            {
                CswC3Params           CswC3Params     = new CswC3Params();
                CswNbtC3ClientManager C3ClientManager = new CswNbtC3ClientManager(_CswNbtResources, CswC3Params);
                SearchClient          C3SearchClient  = C3ClientManager.initializeC3Client();
                if (null != C3SearchClient)
                {
                    string C3Version = C3ClientManager.getCurrentC3Version();
                    ComponentObj.Add(new JProperty("ChemCatCentral", new JObject(
                                                       new JProperty("name", "ChemCatCentral"),
                                                       new JProperty("version", Regex.Replace(C3Version, "_", " ")),
                                                       new JProperty("copyright", "Copyright &copy; ChemSW, Inc. 2005-" + ThisYear))));

                    // Add the datasource import dates (if they are available to the user and/or the module is enabled
                    CswC3ServiceLogicGetDataSourcesDataSource[] DataSourceDates = C3ClientManager.getDataSourceDates();
                    if (null != DataSourceDates)
                    {
                        JObject DSDatesObj = new JObject();
                        foreach (CswC3ServiceLogicGetDataSourcesDataSource ds in DataSourceDates)
                        {
                            if (ds.DataType == "Extra Chemical")
                            {
                                switch (ds.DataSourceName)
                                {
                                case "FireDb":
                                    if (_CswNbtResources.Modules.IsModuleEnabled(CswEnumNbtModuleName.FireDbSync))
                                    {
                                        DSDatesObj[ds.DataSourceName] = new JObject(new JProperty("componentName", ds.DataSourceName), new JProperty("value", ds.ImportDate));
                                    }
                                    break;

                                case "PCID":
                                    if (_CswNbtResources.Modules.IsModuleEnabled(CswEnumNbtModuleName.PCIDSync))
                                    {
                                        DSDatesObj[ds.DataSourceName] = new JObject(new JProperty("componentName", ds.DataSourceName), new JProperty("value", ds.ImportDate));
                                    }
                                    break;
                                } //switch
                            }
                            else
                            {
                                DSDatesObj[ds.DataSourceName] = new JObject(new JProperty("componentName", ds.DataSourceName), new JProperty("value", ds.ImportDate));
                            }
                        }
                        ret.Add(new JProperty("dsDates", DSDatesObj));
                    }
                }//if( C3ClientManager.checkC3ServiceReferenceStatus() )
            }
            #endregion ChemCatCentral Products Versions

            #region ACD Version
            if (_CswNbtResources.Modules.IsModuleEnabled(CswEnumNbtModuleName.C3ACD))
            {
                CswC3Params           CswC3Params     = new CswC3Params();
                CswNbtC3ClientManager C3ClientManager = new CswNbtC3ClientManager(_CswNbtResources, CswC3Params);
                SearchClient          C3SearchClient  = C3ClientManager.initializeC3Client();
                if (null != C3SearchClient)
                {
                    CswRetObjSearchResults Results = C3SearchClient.getACDVersion(CswC3Params);
                    if (null != Results)
                    {
                        ComponentObj.Add(new JProperty("ACD", new JObject(
                                                           new JProperty("name", "Available Chemicals Directory (ACD)"),
                                                           new JProperty("version", Regex.Replace(Results.ACDVersion, "_", " ")),
                                                           new JProperty("copyright", "Copyright &copy; Accelrys, Inc. 1983-" + ThisYear))));
                    }
                }
            }
            #endregion ACD Version


            SortedList <string, CswSessionsListEntry> sessions = _CswSessionResources.CswSessionManager.SessionsList.AllSessions;
            CswDateTime loginDate = new CswDateTime(_CswNbtResources);
            foreach (var entry in sessions)
            {
                CswSessionsListEntry sessionEntry = entry.Value;
                if (sessionEntry.UserName.Equals(_CswNbtResources.CurrentUser.Username))
                {
                    loginDate.FromClientDateString(sessionEntry.LoginDate.ToString());
                }
            }

            JObject UserObj = new JObject();
            UserObj["customerid"]   = new JObject(new JProperty("componentName", "Customer ID:"), new JProperty("value", _CswNbtResources.AccessId));
            UserObj["loggedinas"]   = new JObject(new JProperty("componentName", "Logged in as:"), new JProperty("value", _CswNbtResources.CurrentUser.Username));
            UserObj["sessionsince"] = new JObject(new JProperty("componentName", "Session since:"), new JProperty("value", loginDate.ToDateTime().ToString()));

            ret.Add(new JProperty("userProps", UserObj));

            return(ret);
        } // makeVersionJson()