Exemplo n.º 1
0
        private bool CreateDriverPackge()
        {
            string query = string.Format("SELECT * FROM SMS_DriverPackage WHERE NAME = '{0}'", Name);

            packageObject = Utility.GetFirstWMIInstance(connectionManager, query);

            if (packageObject == null)
            {
                IResultObject instance = connectionManager.CreateInstance("SMS_DriverPackage");
                instance["Name"].StringValue           = Name;
                instance["Description"].StringValue    = "";
                instance["PkgSourceFlag"].IntegerValue = 2;
                instance["PkgSourcePath"].StringValue  = Target;
                instance["PkgFlags"].IntegerValue     |= 16777216;
                // this is only supported on 1810 and above
                if (instance.PropertyList.ContainsKey("DriverManufacturer"))
                {
                    instance["DriverManufacturer"].StringValue = Vendor;
                }
                instance["Version"].StringValue = FileVersion;
                try
                {
                    instance.Put();
                    instance.Get();
                }
                catch (SmsQueryException ex)
                {
                    string str;
                    switch (ex.ExtendStatusErrorCode)
                    {
                    case 4:
                        str = "The driver package storage path is not empty.";
                        break;

                    case 1078462229:
                        str = "The system does not have read or write permissions to the driver package's source path.";
                        break;

                    default:
                        str = "An error occurred while importing the selected driver package.";
                        break;
                    }
                    Exception.Add(new SystemException(str));

                    return(false);
                }

                string folder = registry.ReadString("DriverPackageConsoleFolder");
                if (folder == "%MANUFACTURER%")
                {
                    folder = Vendor;
                }

                Utility.AddObjectToFolder(connectionManager, folder, instance["PackageID"].StringValue, 23);

                packageObject = instance;
            }

            return(true);
        }
Exemplo n.º 2
0
        private bool CreateDriverCategory()
        {
            categoryObject = GetDriverCategory();

            if (categoryObject == null)
            {
                IResultObject instance = connectionManager.CreateInstance("SMS_CategoryInstance");
                instance["CategoryInstance_UniqueID"].StringValue = string.Format("DriverCategories: {0}", Guid.NewGuid().ToString());
                instance["CategoryTypeName"].StringValue          = "DriverCategories";
                List <IResultObject> list = new List <IResultObject>();
                IResultObject        embeddedObjectInstance = connectionManager.CreateEmbeddedObjectInstance("SMS_Category_LocalizedProperties");
                embeddedObjectInstance["CategoryInstanceName"].StringValue = Name;
                embeddedObjectInstance["LocaleID"].IntegerValue            = 0;
                list.Add(embeddedObjectInstance);
                instance.SetArrayItems("LocalizedInformation", list);
                try
                {
                    instance.Put();
                    instance.Get();
                }
                catch (SmsQueryException ex)
                {
                    ManagementException mgmtException = ex.InnerException as ManagementException;
                    Exception.Add(new SystemException(mgmtException.ErrorInformation["Description"].ToString()));
                    return(false);
                }

                categoryObject = instance;
            }

            return(true);
        }
Exemplo n.º 3
0
        public bool UpdatePackageVersion()
        {
            string query = string.Format("SELECT * FROM SMS_DriverPackage WHERE NAME = '{0}'", Name);

            packageObject = Utility.GetFirstWMIInstance(connectionManager, query);

            if (packageObject != null)
            {
                // this is only supported on 1810 and above
                if (packageObject.PropertyList.ContainsKey("DriverManufacturer"))
                {
                    packageObject["DriverManufacturer"].StringValue = Vendor;
                }
                packageObject["Version"].StringValue = FileVersion;

                try
                {
                    packageObject.Put();
                    packageObject.Get();

                    return(true);
                }
                catch (SmsQueryException ex)
                {
                    Exception.Add(ex);

                    return(false);
                }
            }

            return(false);
        }
Exemplo n.º 4
0
        public bool AddDriversToDriverPack()
        {
            List <int>    contentIDs     = new List <int>();
            List <string> packageSources = new List <string>();

            foreach (KeyValuePair <string, Driver> driver in Drivers)
            {
                if (driver.Value.Import && driver.Value.Object != null)
                {
                    string query = string.Format("SELECT ContentID FROM SMS_CIToContent WHERE CI_ID='{0}'", driver.Value.Object["CI_ID"].IntegerValue);

                    foreach (IResultObject resultObject in connectionManager.QueryProcessor.ExecuteQuery(query))
                    {
                        contentIDs.Add(resultObject["ContentID"].IntegerValue);
                    }

                    packageSources.Add(driver.Value.Object["ContentSourcePath"].StringValue);
                }
            }

            Dictionary <string, object> methodParameters = new Dictionary <string, object>
            {
                { "bRefreshDPs", true },
                { "ContentIDs", contentIDs.ToArray() },
                { "ContentSourcePath", packageSources.ToArray() }
            };

            try
            {
                Package.ExecuteMethod("AddDriverContent", methodParameters);
            }
            catch (SmsException ex)
            {
                if (ex is SmsQueryException)
                {
                    ManagementException mgmtExcept = ex.InnerException as ManagementException;
                    Exception.Add(new SystemException(mgmtExcept.ErrorInformation["Description"].ToString()));
                }
                else
                {
                    Exception.Add(ex);
                }

                return(false);
            }

            return(true);
        }
Exemplo n.º 5
0
 public void CreateHashFile()
 {
     try
     {
         string[] fileList = Directory.GetFiles(Source, "*.hash");
         foreach (string file in fileList)
         {
             File.Delete(file);
         }
         File.Create(Path.Combine(Source, Hash + ".hash"));
     }
     catch
     {
         Exception.Add(new SystemException("Cannot create Hash file."));
     }
 }
Exemplo n.º 6
0
        public string GetVersionFromFile()
        {
            try
            {
                string[] fileList = Directory.GetFiles(Source, "*.version");
                if (fileList.Length >= 1)
                {
                    string str = Path.GetFileName(fileList.FirstOrDefault());
                    FileVersion = str.Split('.')[0];
                }
            }
            catch
            {
                Exception.Add(new SystemException("Cannot get version from file."));
            }

            return(FileVersion);
        }
        private void should_merge_non_generic_collections()
        {
            var data1 = new Exception().Data;

            data1.Clear();
            data1.Add("blob", "thang");
            var blob = new { Things = data1 };

            var data2 = new Exception().Data;

            data2.Clear();
            data2.Add("blob", "thang2");
            var blob2 = new { Things = data2 };

            var dictionary = ObjectMerging.Flatten(new object[] { blob, blob2 });

            Assert.True(dictionary.ContainsKey("Things"));
            Assert.Collection <object>((IEnumerable <object>)dictionary["Things"],
                                       id => Assert.Equal(new DictionaryEntry("blob", "thang"), id),
                                       id => Assert.Equal(new DictionaryEntry("blob", "thang2"), id));
        }
Exemplo n.º 8
0
        private bool CreatePackge()
        {
            string query = string.Format("SELECT * FROM SMS_Package WHERE NAME = '{0}'", Name);

            packageObject = Utility.GetFirstWMIInstance(connectionManager, query);

            if (packageObject == null)
            {
                IResultObject instance = connectionManager.CreateInstance("SMS_Package");
                instance["Name"].StringValue           = Name;
                instance["Description"].StringValue    = "";
                instance["PkgSourceFlag"].IntegerValue = 2;
                instance["PkgSourcePath"].StringValue  = Target;
                instance["PkgFlags"].IntegerValue     |= 16777216;
                instance["Manufacturer"].StringValue   = Vendor;
                instance["Version"].StringValue        = FileVersion;
                try
                {
                    instance.Put();
                    instance.Get();
                }
                catch (SmsQueryException ex)
                {
                    Exception.Add(ex);

                    return(false);
                }

                Utility.AddObjectToFolder(connectionManager, registry.ReadString("LegacyConsoleFolder"), instance["PackageID"].StringValue, 2);

                packageObject = instance;
            }

            if (!Directory.Exists(Target))
            {
                Directory.CreateDirectory(Target);
            }

            return(true);
        }
Exemplo n.º 9
0
        public bool UpdatePackageVersion()
        {
            if (packageObject != null)
            {
                packageObject["Manufacturer"].StringValue = Vendor;
                packageObject["Version"].StringValue      = FileVersion;

                try
                {
                    packageObject.Put();
                    packageObject.Get();

                    return(true);
                }
                catch (SmsQueryException ex)
                {
                    Exception.Add(ex);

                    return(false);
                }
            }

            return(false);
        }