Esempio n. 1
0
 private void AddIsapiHandler(PropertyValueCollection propValues, string isapi)
 {
     //1修改成5,保证设置-version参数为4.0的情况下时,可以指定asp.net为4.0 2013-11-07 李久彬
     //propValues.Add(".ajax," + isapi + ",1,GET,HEAD,POST,DEBUG");
     propValues.Add(".ajax," + isapi + ",5,GET,HEAD,POST,DEBUG");
     propValues.Add(".gspx," + isapi + ",5,GET,HEAD,POST,DEBUG");
     if (IISBaseConfig.GetIISVersion() == 6)
     {
         //propValues.Add(string.Format("*,{0},4,全部", isapi));//修改为0,表示默认“确认文件是否存在”没有勾选  2013-11-12
         propValues.Add(string.Format("*,{0},0,全部", isapi));
     }
 }
        protected override void PropertySet(PSProperty property, object setValue, bool convertIfPossible)
        {
            PropertyValueCollection adapterData = property.adapterData as PropertyValueCollection;

            if (adapterData != null)
            {
                try
                {
                    adapterData.Clear();
                }
                catch (COMException exception)
                {
                    if ((exception.ErrorCode != -2147467259) || (setValue == null))
                    {
                        throw;
                    }
                }
                IEnumerable enumerable = LanguagePrimitives.GetEnumerable(setValue);
                if (enumerable == null)
                {
                    adapterData.Add(setValue);
                }
                else
                {
                    foreach (object obj2 in enumerable)
                    {
                        adapterData.Add(obj2);
                    }
                }
            }
            else
            {
                DirectoryEntry baseObject  = (DirectoryEntry)property.baseObject;
                ArrayList      list        = new ArrayList();
                IEnumerable    enumerable2 = LanguagePrimitives.GetEnumerable(setValue);
                if (enumerable2 == null)
                {
                    list.Add(setValue);
                }
                else
                {
                    foreach (object obj3 in enumerable2)
                    {
                        list.Add(obj3);
                    }
                }
                baseObject.InvokeSet(property.name, list.ToArray());
            }
        }
        //活动矩阵定义的属性优先于活动模板定义的属性,矩阵中没有设置的属性,则使用活动模版的属性
        private static void MergeDynamicActivitiesProperties(WfCreateActivityParamCollection createActivityParams, IWfActivityDescriptor templateActDesp)
        {
            foreach (WfCreateActivityParam cap in createActivityParams)
            {
                PropertyValueCollection templateProperties = new PropertyValueCollection();

                foreach (PropertyValue pv in templateActDesp.Properties)
                {
                    if (cap.RoleDefineActivityPropertyNames.Exists(name => pv.Definition.Name == name))
                    {
                        if (cap.Template.Properties.ContainsKey(pv.Definition.Name))
                        {
                            templateProperties.Add(cap.Template.Properties[pv.Definition.Name]);
                        }
                    }
                    else
                    {
                        templateProperties.Add(pv);
                    }
                }

                cap.Template.Properties.ReplaceExistedPropertyValues(templateProperties);

                cap.Template.RelativeLinks.Clear();
                cap.Template.RelativeLinks.CopyFrom(templateActDesp.RelativeLinks);

                cap.Template.Variables.Clear();
                cap.Template.Variables.CopyFrom(templateActDesp.Variables);

                //cap.Template.EnterEventReceivers.Clear();
                cap.Template.EnterEventReceivers.CopyFrom(templateActDesp.EnterEventReceivers);

                //cap.Template.LeaveEventReceivers.Clear();
                cap.Template.LeaveEventReceivers.CopyFrom(templateActDesp.LeaveEventReceivers);

                cap.Template.EnterEventExecuteServices.Clear();
                cap.Template.EnterEventExecuteServices.CopyFrom(templateActDesp.EnterEventExecuteServices);

                cap.Template.LeaveEventExecuteServices.Clear();
                cap.Template.LeaveEventExecuteServices.CopyFrom(templateActDesp.LeaveEventExecuteServices);

                cap.Template.WithdrawExecuteServices.Clear();
                cap.Template.WithdrawExecuteServices.CopyFrom(templateActDesp.WithdrawExecuteServices);

                cap.Template.BeWithdrawnExecuteServices.Clear();
                cap.Template.BeWithdrawnExecuteServices.CopyFrom(templateActDesp.BeWithdrawnExecuteServices);
            }
        }
Esempio n. 4
0
        void ExportGeometry(IGeometry g)
        {
            // c.f. FdoToolbox bulk copy? - FdoBatchedOutputOperation
            using (IInsert cmd = m_Connection.CreateCommand(CommandType.CommandType_Insert) as IInsert)
            {
                cmd.SetFeatureClassName("FC");

                PropertyValueCollection pvc = cmd.PropertyValues;

                //PropertyValue pvId = new PropertyValue();
                //pvId.SetName("ID");
                //pvId.Value = new Int32Value(id);
                //pvc.Add(pvId);

                GeometryValue gv     = new GeometryValue(m_Factory.GetFgf(g));
                PropertyValue pvGeom = new PropertyValue();
                pvGeom.SetName("Geometry");
                pvGeom.Value = gv;
                pvc.Add(pvGeom);

                try
                {
                    IFeatureReader reader = cmd.Execute();
                    reader.Dispose();
                    m_NumOk++;
                }

                catch
                {
                    m_NumFail++;
                }
            }
        }
Esempio n. 5
0
    /// <summary>
    /// Adds a host header value to a specified website. WARNING: NO ERROR CHECKING IS PERFORMED IN THIS EXAMPLE.
    /// YOU ARE RESPONSIBLE FOR THAT EVERY ENTRY IS UNIQUE
    /// </summary>
    /// <param name="hostHeader">The host header. Must be in the form IP:Port:Hostname </param>
    /// <param name="websiteID">The ID of the website the host header should be added to </param>
    public static void AddHostHeader(string hostHeader, string websiteID)
    {
        DirectoryEntry site = new DirectoryEntry("IIS://localhost/w3svc/" + websiteID);

        try
        {
            //Get everything currently in the serverbindings propery.
            PropertyValueCollection serverBindings = site.Properties["ServerBindings"];

            //Add the new binding
            serverBindings.Add(hostHeader);

            //Create an object array and copy the content to this array
            Object [] newList = new Object[serverBindings.Count];
            serverBindings.CopyTo(newList, 0);

            //Write to metabase
            site.Properties["ServerBindings"].Value = newList;

            //Commit the changes
            site.CommitChanges();
        }
        catch (Exception e)
        {
            Console.WriteLine(e);
        }
    }
Esempio n. 6
0
        /// <summary>
        /// 设置Customer HTTP header
        /// </summary>
        private bool SetCustomHTTPheaders(string metabasePath, string customHeaderName, string customHeaderNameValue)
        {
            try
            {
                DirectoryEntry          path       = new DirectoryEntry(metabasePath);
                PropertyValueCollection propValues = path.Properties["HttpCustomHeaders"];

                object exists = null;
                foreach (object value in propValues)
                {
                    string[] a;
                    a = value.ToString().Split(':');
                    if (a[0] == customHeaderName.Trim())
                    {
                        exists = value;
                    }
                }

                if (null != exists)
                {
                    propValues.Remove(exists);
                }

                string saveValue = customHeaderName + ":" + customHeaderNameValue;
                propValues.Add((object)saveValue);
                path.CommitChanges();

                return(true);
            }
            catch (Exception ex)
            {
                throw new IISException("Set Customer HTTP header error - " + ex.Message, ex, IISVersion);
            }
        }
Esempio n. 7
0
        private static void SetMimeType(DirectoryEntry vdirObj, string newExtension, string newMimeType)
        {
            PropertyValueCollection propValues = vdirObj.Properties["MimeMap"];
            object       exists     = null;
            const string cMimeType  = "MimeType";
            const string cExtension = "Extension";

            foreach (object value in propValues)
            {
                if (newExtension == GetObjectProp(value, cExtension))
                {
                    exists = value;
                }
            }

            if (exists != null)
            {
                if (newMimeType == GetObjectProp(exists, cMimeType))
                {
                    return;
                }
                propValues.Remove(exists);
            }

            object newObj = CreateObject("MimeMap");

            SetObjectProp(newObj, cExtension, newExtension);
            SetObjectProp(newObj, cMimeType, newMimeType);
            propValues.Add(newObj);
            vdirObj.CommitChanges();
        }
Esempio n. 8
0
    public bool AddHostHeader(string hostHeader)
    {
        if (hostHeader.IndexOf(':') < 0)
        {
            return(false);
        }

        using (DirectoryEntry site = new DirectoryEntry("IIS://" + _serverName + "/w3svc/" + GetWebSiteId()))
        {
            try
            {
                PropertyValueCollection serverBindings = site.Properties["ServerBindings"];

                if (ExistHostHeader(hostHeader))
                {
                    return(false);
                }

                serverBindings.Add(hostHeader);

                Object[] newList = new Object[serverBindings.Count];
                serverBindings.CopyTo(newList, 0);

                site.Properties["ServerBindings"].Value = newList;

                site.CommitChanges();
                return(true);
            }
            catch
            {
                return(false);
            }
        }
    }
Esempio n. 9
0
        /// <summary>
        /// 增加站点主机头(根据站点号,也就是站点标识)
        /// </summary>
        /// <param name="SiteNum"></param>
        /// <param name="IPAddress"></param>
        /// <param name="Port"></param>
        /// <param name="Url"></param>
        public void AddHostHeader(long SiteNum, string IPAddress, string Port, string Url)
        {
            if (SiteNum < 0)
            {
                throw new Exception("IIS 站点号“" + SiteNum.ToString() + "”打开失败。");
            }

            string         entry = String.Format("IIS://{0}/w3svc/{1}", HostName, SiteNum);
            DirectoryEntry site  = GetDirectoryEntry(entry);

            if (site == null)
            {
                throw new Exception("IIS 站点号“" + SiteNum.ToString() + "”打开失败。");
            }

            PropertyValueCollection serverBindings = site.Properties["ServerBindings"];

            string headerStr = string.Format("{0}:{1}:{2}", IPAddress, Port, Url);

            if (!serverBindings.Contains(headerStr))
            {
                serverBindings.Add(headerStr);
                site.CommitChanges();
            }
        }
        public PropertyValueCollection ToPropertyValues()
        {
            PropertyValueCollection result = new PropertyValueCollection();

            this.ForEach(spv => result.Add((PropertyValue)spv));

            return(result);
        }
Esempio n. 11
0
        //
        // PAPI --> S.DS (LDAP or WinNT) conversion routines
        //

        static internal void MultiStringToDirectoryEntryConverter(Principal p, string propertyName, DirectoryEntry de, string suggestedProperty)
        {
            PrincipalValueCollection <string> trackingList = (PrincipalValueCollection <string>)p.GetValueForProperty(propertyName);

            if (p.unpersisted && trackingList == null)
            {
                return;
            }

            List <string> insertedValues = trackingList.Inserted;
            List <string> removedValues  = trackingList.Removed;
            List <Pair <string, string> > changedValues = trackingList.ChangedValues;

            PropertyValueCollection properties = de.Properties[suggestedProperty];

            // We test to make sure the change hasn't already been applied to the PropertyValueCollection,
            // because PushChangesToNative can be called multiple times prior to committing the changes and
            // we want to maintain idempotency
            foreach (string value in removedValues)
            {
                if (value != null && properties.Contains(value))
                {
                    properties.Remove(value);
                }
            }

            foreach (Pair <string, string> changedValue in changedValues)
            {
                // Remove the original value and add in the new value
                Debug.Assert(changedValue.Left != null);    // since it came from the system
                properties.Remove(changedValue.Left);

                if (changedValue.Right != null && !properties.Contains(changedValue.Right))
                {
                    properties.Add(changedValue.Right);
                }
            }

            foreach (string value in insertedValues)
            {
                if (value != null && !properties.Contains(value))
                {
                    properties.Add(value);
                }
            }
        }
        private static PropertyValueCollection PrepareProperties()
        {
            PropertyValueCollection properties = new PropertyValueCollection();

            PropertyDefine pd1 = new PropertyDefine();

            pd1.Name = "P1";

            properties.Add(new PropertyValue(pd1));

            PropertyDefine pd2 = new PropertyDefine();

            pd2.Name = "P2";

            properties.Add(new PropertyValue(pd2));

            return(properties);
        }
Esempio n. 13
0
        internal static void MultiStringToDirectoryEntryConverter(Principal p, string propertyName, DirectoryEntry de, string suggestedProperty)
        {
            PrincipalValueCollection <string> valueForProperty = (PrincipalValueCollection <string>)p.GetValueForProperty(propertyName);

            if (!p.unpersisted || valueForProperty != null)
            {
                List <string> inserted = valueForProperty.Inserted;
                List <string> removed  = valueForProperty.Removed;
                List <Pair <string, string> > changedValues = valueForProperty.ChangedValues;
                PropertyValueCollection       item          = de.Properties[suggestedProperty];
                foreach (string str in removed)
                {
                    if (str == null || !item.Contains(str))
                    {
                        continue;
                    }
                    item.Remove(str);
                }
                foreach (Pair <string, string> changedValue in changedValues)
                {
                    item.Remove(changedValue.Left);
                    if (changedValue.Right == null || item.Contains(changedValue.Right))
                    {
                        continue;
                    }
                    item.Add(changedValue.Right);
                }
                foreach (string str1 in inserted)
                {
                    if (str1 == null || item.Contains(str1))
                    {
                        continue;
                    }
                    item.Add(str1);
                }
                return;
            }
            else
            {
                return;
            }
        }
Esempio n. 14
0
        /// <summary>
        /// 转换为属性值集合
        /// </summary>
        /// <returns></returns>
        public PropertyValueCollection ToDynamicProperties()
        {
            PropertyValueCollection properties = new PropertyValueCollection();

            foreach (DynamicEntityField field in this.Fields)
            {
                properties.Add(field.ToDynamicPropertyValue());
            }

            return(properties);
        }
Esempio n. 15
0
        public static void AddHostHeader(int siteid, string ip, int port, string domain)//增加主机头(站点编号.ip.端口.域名)
        {
            DirectoryEntry          site           = new DirectoryEntry("IIS://localhost/W3SVC/" + siteid);
            PropertyValueCollection serverBindings = site.Properties["ServerBindings"];
            string headerStr = string.Format("{0}:{1}:{2}", ip, port, domain);

            if (!serverBindings.Contains(headerStr))
            {
                serverBindings.Add(headerStr);
            }
            site.CommitChanges();
        }
Esempio n. 16
0
        private static void FillGroupMembersByOguIDs(IEnumerable <string> oguObjectIDs, PropertyValueCollection adGroupMembers, SynchronizeContext context)
        {
            IEnumerable <SearchResult> result = SynchronizeHelper.GetSearchResultsByIDs(context.ADHelper, context.IDMapper.GetMappedADObjectIDs(oguObjectIDs),
                                                                                        new string[] { "distinguishedName" }, oguObjectIDs.Count());

            foreach (SearchResult sr in result)
            {
                SynchronizeContext.Current.ExtendLockTime();

                adGroupMembers.Add(sr.Properties["distinguishedName"][0]);
            }
        }
        /// <summary>
        /// 转换为PropertyValue集合
        /// </summary>
        /// <returns></returns>
        public PropertyValueCollection ToPropertyValues()
        {
            PropertyValueCollection result = new PropertyValueCollection();

            this.OrderBy(p => p.SortOrder).ForEach(spv =>
            {
                PropertyValue pv = spv.Definition.ToDynamicPropertyValue();
                pv.StringValue   = spv.StringValue;
                result.Add(pv);
            });

            return(result);
        }
Esempio n. 18
0
        public static void SDFUpdate(string SDFFile, string schemaName)
        {
            Debug.Write("SDFH", "Update Data module running...");
            try
            {
                IConnection con = SDFHelper.SDFConnection(SDFFile);
                con.Open();
                using (con)
                {
                    using (osgeo_command.Feature.IUpdate update_data = con.CreateCommand(osgeo_command.CommandType.CommandType_Update) as osgeo_command.Feature.IUpdate)
                    {
                        //set the target schema
                        update_data.SetFeatureClassName("Civil_schema:Pipes");
                        //var filter = "('[Name]'='R-1P1')";
                        var filter = "(Name='R-1P1')";
                        update_data.SetFilter(filter);
                        Debug.Write("SDFH", "Updating...");
                        PropertyValueCollection pcoll = update_data.PropertyValues;

                        osgeo_command.PropertyValue propvalue = null;
                        propvalue = new osgeo_command.PropertyValue();

                        //ValueExpression expression = (ValueExpression)Expression.Parse("Iron");
                        ValueExpression expression = new StringValue("Iron");

                        //propvalue.SetName(prop.Name);
                        propvalue = new PropertyValue("PartSizeName", expression);
                        //propvalue.SetName("PipeType");

                        pcoll.Add(propvalue);

                        if (1 != update_data.Execute())
                        {
                            Debug.Fail("test debug fail message");
                        }
                    }
                }
            }
            catch (OSGeo.FDO.Common.Exception ge)
            {
                bool ok = ge.Message.Contains("read-only");
                Debug.Write(ge.ToString());
            }
            catch (SystemException ex)
            {
                bool ok = ex.Message.Contains("read-only");
                Debug.Write(ex.ToString());
            }
        }
Esempio n. 19
0
        /// <summary>
        /// 添加域名绑定
        /// </summary>
        /// <param name="serverName">服务器名称</param>
        /// <param name="siteid">站点编号</param>
        /// <param name="ip">ip</param>
        /// <param name="port">端口</param>
        /// <param name="domain">域名</param>
        public static void AddHostHeader(string serverName, int siteid, string ip, int port, string domain)
        {
            DirectoryEntry          site           = new DirectoryEntry("IIS://" + serverName + "/W3SVC/" + siteid);
            PropertyValueCollection serverBindings = site.Properties["ServerBindings"];
            string headerStr = string.Format("{0}:{1}:{2}", ip, port, domain);

            if (!serverBindings.Contains(headerStr))
            {
                serverBindings.Add(headerStr);
            }
            //默认情况下,对缓存进行本地更改。修改或添加节点之后,
            //必须调用 CommitChanges 方法,以便提交更改,将它们保存到树中。
            //如果在调用 CommitChanges 之前调用 RefreshCache,则将丢失对属性缓存的任何未提交的更改。
            site.CommitChanges();
        }
Esempio n. 20
0
        private static void UpdateMetaBaseProperty(DirectoryEntry entry, string metaBasePropertyName, string metaBaseProperty)
        {
            if (metaBaseProperty.IndexOf('|') == -1)
            {
                string propertyTypeName;
                using (DirectoryEntry di = new DirectoryEntry(entry.SchemaEntry.Parent.Path + "/" + metaBasePropertyName))
                {
                    propertyTypeName = (string)di.Properties["Syntax"].Value;
                }

                if (string.Compare(propertyTypeName, "binary", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    object[] metaBasePropertyBinaryFormat = new object[metaBaseProperty.Length / 2];
                    for (int i = 0; i < metaBasePropertyBinaryFormat.Length; i++)
                    {
                        metaBasePropertyBinaryFormat[i] = metaBaseProperty.Substring(i * 2, 2);
                    }

                    PropertyValueCollection propValues = entry.Properties[metaBasePropertyName];
                    propValues.Clear();
                    propValues.Add(metaBasePropertyBinaryFormat);
                    entry.CommitChanges();
                }
                else
                {
                    if (string.Compare(metaBasePropertyName, "path", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        DirectoryInfo f = new DirectoryInfo(metaBaseProperty);
                        metaBaseProperty = f.FullName;
                    }

                    entry.Invoke("Put", metaBasePropertyName, metaBaseProperty);
                    entry.Invoke("SetInfo");
                }
            }
            else
            {
                entry.Invoke("Put", metaBasePropertyName, string.Empty);
                entry.Invoke("SetInfo");
                string[] metabaseProperties = metaBaseProperty.Split('|');
                foreach (string metabasePropertySplit in metabaseProperties)
                {
                    entry.Properties[metaBasePropertyName].Add(metabasePropertySplit);
                }

                entry.CommitChanges();
            }
        }
Esempio n. 21
0
 public override void SaveDirectoryObject(DirectoryObject directoryObject)
 {
     if (directoryObject == null)
     {
         throw new ArgumentNullException("directoryObject");
     }
     using (DirectoryEntry directoryEntry = GetDirectoryEntry()) {
         string filter = string.Format(CultureInfo.InvariantCulture, FilterAndFormat, BaseFilter + string.Format(CultureInfo.InvariantCulture, FilterFormat, this.IdentifyingPropertyName, directoryObject.Id));
         using (DirectorySearcher directorySearcher = new DirectorySearcher(
                    directoryEntry,
                    filter,
                    PropertyNames,
                    SearchScope.Subtree)) {
             using (DirectoryEntry directoryEntryWrite = directorySearcher.FindOne().GetDirectoryEntry()) {
                 bool commitChanges = false;
                 foreach (string propertyName in this.PropertyNames)
                 {
                     PropertyValueCollection pvc = directoryEntryWrite.Properties[propertyName];
                     string newValue             = directoryObject[propertyName];
                     if (pvc.Value != null)
                     {
                         if (!pvc.Value.ToString().Equals(newValue))
                         {
                             if (!string.IsNullOrEmpty(newValue))
                             {
                                 pvc.Value = newValue;
                             }
                             else
                             {
                                 pvc.RemoveAt(0);
                             }
                             commitChanges = true;
                         }
                     }
                     else if (!string.IsNullOrEmpty(newValue))
                     {
                         pvc.Add(newValue);
                         commitChanges = true;
                     }
                 }
                 if (commitChanges)
                 {
                     directoryEntryWrite.CommitChanges();
                 }
             }
         }
     }
 }
Esempio n. 22
0
        /// <summary>
        /// 转换为PropertyValue集合
        /// </summary>
        /// <returns></returns>
        public PropertyValueCollection ToPropertyValues()
        {
            PropertyValueCollection result = new PropertyValueCollection();

            this.OrderBy(p => p.SortNo).ForEach(spv =>
            {
                PropertyValue pv = spv.ToDynamicPropertyValue();
                //为PropertyForm布局是添加默认的section
                if (string.IsNullOrEmpty(pv.Definition.Category))
                {
                    pv.Definition.Category = "section1";
                }
                result.Add(pv);
            });

            return(result);
        }
		public void PropertyValueCollectionSerializeTest()
		{
			PropertyValueCollection pvc = new PropertyValueCollection();

			pvc.Add(PreparePropertyValue());

			XElementFormatter formatter = new XElementFormatter();

			XElement root = formatter.Serialize(pvc);

			Console.WriteLine(root.ToString());

			PropertyValueCollection newPvc = (PropertyValueCollection)formatter.Deserialize(root);

			Assert.AreEqual(pvc.Count, newPvc.Count);
			Assert.AreEqual(pvc[0].StringValue, newPvc[pvc[0].Definition.Name].StringValue);
		}
Esempio n. 24
0
        public void PropertyValueCollectionSerializeTest()
        {
            PropertyValueCollection pvc = new PropertyValueCollection();

            pvc.Add(PreparePropertyValue());

            XElementFormatter formatter = new XElementFormatter();

            XElement root = formatter.Serialize(pvc);

            Console.WriteLine(root.ToString());

            PropertyValueCollection newPvc = (PropertyValueCollection)formatter.Deserialize(root);

            Assert.AreEqual(pvc.Count, newPvc.Count);
            Assert.AreEqual(pvc[0].StringValue, newPvc[pvc[0].Definition.Name].StringValue);
        }
Esempio n. 25
0
        public string AddHostHeader(string websiteName, string ipAddress, string port, string hostname)
        {
            string         websiteID   = GetWebsiteID(websiteName);
            string         websitePath = "IIS://" + mServer + "/w3svc/" + websiteID;
            DirectoryEntry website     = null;

            try
            {
                website = new DirectoryEntry(websitePath);
            }
            catch (Exception error)
            {
                throw new Exception("Error creating the web directory entry.\n" + error.Message + "\n" + error.InnerException);
            }

            PropertyValueCollection websiteBindings = null;

            try
            {
                websiteBindings = website.Properties["ServerBindings"];
            }
            catch (Exception error)
            {
                throw new Exception("Error getting the host header listing.\n" + error.Message + "\n" + error.InnerException);
            }

            string hostHeader = string.Format("{0}:{1}:{2}", ipAddress, port, hostname);

            if (websiteBindings.Contains(hostHeader))
            {
                return("exists");
            }

            try
            {
                websiteBindings.Add(hostHeader);
                website.CommitChanges();
            }
            catch (System.Exception error)
            {
                throw new Exception("Error adding the host header.\n" + error.Message + "\n" + error.InnerException);
            }

            return("added");
        }
Esempio n. 26
0
 private void SetPropValue(PropertyValueCollection collection, object value)
 {
     if (null == collection)
     {
         return;
     }
     try
     {
         if (collection.Capacity > 0)
         {
             collection[0] = value;
         }
         else
         {
             collection.Add(value);
         }
     }
     catch
     { }
 }
        protected override void OnAddValue(object value)
        {
            object[] array = value as object[];

            if (array == null)
            {
                array = new object[] { value };
            }

            PropertyValueCollection values =
                DirectoryUtils.GetPropertyValues(Entry, AttributeName);

            foreach (object val in array)
            {
                if (!values.Contains(val))
                {
                    values.Add(val);
                }
            }

            Entry.CommitChanges();
        }
Esempio n. 28
0
        public void AddHostHeader(long SiteNum, string IPAddress, string Port, string Url)
        {
            if (SiteNum < 0L)
            {
                throw new Exception("IIS 站点号“" + SiteNum.ToString() + "”打开失败。");
            }
            string         entryPath      = string.Format("IIS://{0}/w3svc/{1}", this.HostName, SiteNum);
            DirectoryEntry directoryEntry = this.GetDirectoryEntry(entryPath);

            if (directoryEntry == null)
            {
                throw new Exception("IIS 站点号“" + SiteNum.ToString() + "”打开失败。");
            }
            PropertyValueCollection values = directoryEntry.Properties["ServerBindings"];
            string str2 = string.Format("{0}:{1}:{2}", IPAddress, Port, Url);

            if (!values.Contains(str2))
            {
                values.Add(str2);
                directoryEntry.CommitChanges();
            }
        }
        //活动矩阵定义的属性优先于活动模板定义的属性,矩阵中没有设置的属性,则使用活动模版的属性
        private static void MergeDynamicActivitiesProperties(WfCreateActivityParamCollection createActivityParams, IWfActivityDescriptor templateActDesp)
        {
            foreach (WfCreateActivityParam cap in createActivityParams)
            {
                PropertyValueCollection templateProperties = new PropertyValueCollection();

                foreach (PropertyValue pv in templateActDesp.Properties)
                {
                    if (cap.RoleDefineActivityPropertyNames.Exists(name => pv.Definition.Name == name))
                    {
                        if (cap.Template.Properties.ContainsKey(pv.Definition.Name))
                            templateProperties.Add(cap.Template.Properties[pv.Definition.Name]);
                    }
                    else
                        templateProperties.Add(pv);
                }

                cap.Template.Properties.ReplaceExistedPropertyValues(templateProperties);

                cap.Template.RelativeLinks.Clear();
                cap.Template.RelativeLinks.CopyFrom(templateActDesp.RelativeLinks);

                cap.Template.Variables.Clear();
                cap.Template.Variables.CopyFrom(templateActDesp.Variables);

                //cap.Template.EnterEventReceivers.Clear();
                cap.Template.EnterEventReceivers.CopyFrom(templateActDesp.EnterEventReceivers);

                //cap.Template.LeaveEventReceivers.Clear();
                cap.Template.LeaveEventReceivers.CopyFrom(templateActDesp.LeaveEventReceivers);

                cap.Template.EnterEventExecuteServices.Clear();
                cap.Template.EnterEventExecuteServices.CopyFrom(templateActDesp.EnterEventExecuteServices);

                cap.Template.LeaveEventExecuteServices.Clear();
                cap.Template.LeaveEventExecuteServices.CopyFrom(templateActDesp.LeaveEventExecuteServices);

                cap.Template.WithdrawExecuteServices.Clear();
                cap.Template.WithdrawExecuteServices.CopyFrom(templateActDesp.WithdrawExecuteServices);

                cap.Template.BeWithdrawnExecuteServices.Clear();
                cap.Template.BeWithdrawnExecuteServices.CopyFrom(templateActDesp.BeWithdrawnExecuteServices);
            }
        }
Esempio n. 30
0
        private void Prepare(PropertyValueCollection propVals)
        {
            propVals.Clear();
            currentValues.Clear();

            // I do not trust the long-term stability of the PropertyValueCollection
            //
            // So what we do is load it up once with LiteralValue references and manipulate these
            // outside of the collection (via a cached dictionary). We cache everything from the wrapper API 
            // that can be cached in the managed world so that we only have minimal contact with it

            // Omit read-only properties
            using (FdoFeatureService service = _conn.CreateFeatureService())
            {
                ClassDefinition c = service.GetClassByName(this.ClassName);
                foreach (PropertyDefinition p in c.Properties)
                {
                    string name = p.Name;
                    PropertyValue pv = new PropertyValue(name, null);
                    if (p.PropertyType == PropertyType.PropertyType_DataProperty)
                    {
                        DataPropertyDefinition d = p as DataPropertyDefinition;
                        if (!d.ReadOnly && !d.IsAutoGenerated) 
                        {
                            DataValue dv = null;
                            switch (d.DataType)
                            {
                                case DataType.DataType_BLOB:
                                    dv = new BLOBValue();
                                    break;
                                case DataType.DataType_Boolean:
                                    dv = new BooleanValue();
                                    break;
                                case DataType.DataType_Byte:
                                    dv = new ByteValue();
                                    break;
                                case DataType.DataType_CLOB:
                                    dv = new CLOBValue();
                                    break;
                                case DataType.DataType_DateTime:
                                    dv = new DateTimeValue();
                                    break;
                                case DataType.DataType_Decimal:
                                    dv = new DecimalValue();
                                    break;
                                case DataType.DataType_Double:
                                    dv = new DoubleValue();
                                    break;
                                case DataType.DataType_Int16:
                                    dv = new Int16Value();
                                    break;
                                case DataType.DataType_Int32:
                                    dv = new Int32Value();
                                    break;
                                case DataType.DataType_Int64:
                                    dv = new Int64Value();
                                    break;
                                case DataType.DataType_Single:
                                    dv = new SingleValue();
                                    break;
                                case DataType.DataType_String:
                                    dv = new StringValue();
                                    break;
                            }
                            if (dv != null)
                            {
                                pv.Value = dv;
                                propVals.Add(pv);
                            }
                        }
                    }
                    else if (p.PropertyType == PropertyType.PropertyType_GeometricProperty)
                    {
                        GeometricPropertyDefinition g = p as GeometricPropertyDefinition;
                        if (!g.ReadOnly)
                        {
                            GeometryValue gv = new GeometryValue();
                            pv.Value = gv;
                            propVals.Add(pv);
                        }
                    }
                }
                c.Dispose();
            }

            //Load property values into temp dictionary
            foreach (PropertyValue p in propVals)
            {
                currentValues[p.Name.Name] = p.Value as LiteralValue;
            }

            if (propertySnapshot == null)
            {
                propertySnapshot = new List<string>();
                foreach (PropertyValue p in propVals)
                {
                    propertySnapshot.Add(p.Name.Name);
                }
            }
        }
Esempio n. 31
0
        /// <summary>
        /// SetMultiValued method implementation
        /// </summary>
        internal static void SetMultiValued(PropertyValueCollection props, bool ismultivalued, string value)
        {
            if (props == null)
            {
                return;
            }
            if (!ismultivalued)
            {
                if (string.IsNullOrEmpty(value))
                {
                    props.Clear();
                }
                else
                {
                    props.Value = value;
                }
            }
            else
            {
                switch (props.Count)
                {
                case 0:
                    if (!string.IsNullOrEmpty(value))
                    {
                        props.Add(SetMultiValuedHeader(value));
                    }
                    break;

                case 1:
                    if (props.Value == null)
                    {
                        return;
                    }
                    if (props.Value is string)
                    {
                        string so = props.Value as string;
                        if (string.IsNullOrEmpty(value))
                        {
                            props.Remove(so);      // Clean value anyway
                            return;
                        }
                        if (HasSetMultiValued(so))
                        {
                            props.Value = SetMultiValuedHeader(value);
                        }
                        else
                        {
                            props.Add(SetMultiValuedHeader(value));
                        }
                    }
                    break;

                default:
                    int j = props.Count;
                    for (int i = 0; i < j; i++)
                    {
                        if (props[i] != null)
                        {
                            if (props[i] is string)
                            {
                                string so2 = props[i] as string;
                                if (HasSetMultiValued(so2))
                                {
                                    if (string.IsNullOrEmpty(value))
                                    {
                                        props.Remove(so2);
                                    }
                                    else
                                    {
                                        props[i] = SetMultiValuedHeader(value);
                                    }
                                    return;
                                }
                            }
                        }
                    }
                    if (!string.IsNullOrEmpty(value))
                    {
                        props.Add(SetMultiValuedHeader(value));     // Add tagged value if not null
                    }
                    break;
                }
            }
        }
Esempio n. 32
0
        /// <summary>
        /// When overridden in a derived class, executes the task.
        /// </summary>
        /// <returns>
        /// True if the task successfully executed; otherwise, false.
        /// </returns>
        public override bool Execute()
        {
            if (!mapToAspNet && String.IsNullOrEmpty(executablePath))
            {
                Log.LogError("You must either specify a value for ExecutablePath, or set MapToAspNet = True.");
                return(false);
            }
            if (mapToAspNet)
            {
                executablePath     = ToolLocationHelper.GetPathToDotNetFrameworkFile("aspnet_isapi.dll", TargetDotNetFrameworkVersion.VersionLatest);
                enableScriptEngine = true;
            }
            int flags = 0;

            if (enableScriptEngine)
            {
                flags += 1;
            }
            if (verifyFileExists)
            {
                flags += 4;
            }
            if (!extension.StartsWith("."))
            {
                extension = "." + extension;
            }

            DirectoryEntry targetDirectory = null;

            try
            {
                Log.LogMessage(MessageImportance.Normal, Properties.Resources.WebDirectoryScriptMapUpdate, Extension, VirtualDirectoryName, ServerName);

                VerifyIISRoot();

                string targetDirectoryPath = (VirtualDirectoryName == "/")
                    ? targetDirectoryPath = IISServerPath
                    : targetDirectoryPath = IISServerPath + "/" + VirtualDirectoryName;

                targetDirectory = new DirectoryEntry(targetDirectoryPath);

                try
                {
                    string directoryExistsTest = targetDirectory.SchemaClassName;
                }
                catch (COMException)
                {
                    Log.LogError(Properties.Resources.WebDirectoryInvalidDirectory, VirtualDirectoryName, ServerName);
                    return(false);
                }

                PropertyValueCollection scriptMaps = targetDirectory.Properties["ScriptMaps"];
                if (scriptMaps == null)
                {
                    Log.LogError(Properties.Resources.WebDirectorySettingInvalidSetting, VirtualDirectoryName, ServerName, "ScriptMaps");
                    return(false);
                }

                int extensionIndex = -1;
                for (int i = 0; i < scriptMaps.Count; i++)
                {
                    string scriptMap = scriptMaps[i] as string;
                    if (scriptMap == null)
                    {
                        continue;
                    }

                    if (scriptMap.StartsWith(extension + ",", StringComparison.InvariantCultureIgnoreCase))
                    {
                        extensionIndex = i;
                        break;
                    }
                }

                string newVerbs = !String.IsNullOrEmpty(verbs) ?
                                  "," + verbs.Replace(';', ',') :
                                  String.Empty;
                string mappingDetails = String.Format("{0},{1},{2}{3}",
                                                      extension,
                                                      executablePath,
                                                      flags.ToString(),
                                                      newVerbs
                                                      );

                if (extensionIndex >= 0)
                {
                    scriptMaps[extensionIndex] = mappingDetails;
                }
                else
                {
                    scriptMaps.Add(mappingDetails);
                }
                targetDirectory.CommitChanges();
            }
            finally
            {
                if (targetDirectory != null)
                {
                    targetDirectory.Dispose();
                }
            }
            return(true);
        }
Esempio n. 33
0
        /// <summary>
        /// Sets the value of a property coming from a previous call to GetMember
        /// </summary>
        /// <param name="property">PSProperty coming from a previous call to GetMember</param>
        /// <param name="setValue">value to set the property with</param>
        /// <param name="convertIfPossible">instructs the adapter to convert before setting, if the adapter supports conversion</param>
        protected override void PropertySet(PSProperty property, object setValue, bool convertIfPossible)
        {
            PropertyValueCollection values = property.adapterData as PropertyValueCollection;

            if (null != values)
            {
                // This means GetMember returned PropertyValueCollection
                try
                {
                    values.Clear();
                }
                catch (System.Runtime.InteropServices.COMException e)
                {
                    if (e.ErrorCode != unchecked ((int)0x80004005) || (setValue == null))
                    {
                        // When clear is called, DirectoryEntry calls PutEx on AD object with Clear option and Null Value
                        // WinNT provider throws E_FAIL when null value is specified though actually ADS_PROPERTY_CLEAR option is used,
                        // we need to catch  this exception here.
                        // But at the same time we don't want to catch the exception if user explicitly sets the value to null.
                        throw;
                    }
                }

                IEnumerable enumValues = LanguagePrimitives.GetEnumerable(setValue);

                if (enumValues == null)
                {
                    values.Add(setValue);
                }
                else
                {
                    foreach (object objValue in enumValues)
                    {
                        values.Add(objValue);
                    }
                }
            }
            else
            {
                // This means GetMember returned the value from InvokeGet..So set the value using InvokeSet.
                DirectoryEntry entry = (DirectoryEntry)property.baseObject;
                Diagnostics.Assert(entry != null, "Object should be of type DirectoryEntry in DirectoryEntry adapter.");

                List <object> setValues  = new List <object>();
                IEnumerable   enumValues = LanguagePrimitives.GetEnumerable(setValue);

                if (enumValues == null)
                {
                    setValues.Add(setValue);
                }
                else
                {
                    foreach (object objValue in enumValues)
                    {
                        setValues.Add(objValue);
                    }
                }

                entry.InvokeSet(property.name, setValues.ToArray());
            }

            return;
        }
Esempio n. 34
0
        public static IPropertyValueCollection GetStaticProperties(this IResource resource)
        {
            var result = new PropertyValueCollection();
            var prop = new Property();
            prop.Name = "creationdate";
            prop.PropertyType = typeof(DateTime);
            var value = new PropertyValue();
            value.Property = prop;
            value.Value = resource.CreationDate;
            result.Add(value);

            prop = new Property();
            prop.Name = "displayname";
            prop.PropertyType = typeof(string);
            value = new PropertyValue();
            value.Property = prop;
            value.Value = resource.DisplayName;
            result.Add(value);

            prop = new Property();
            prop.Name = "getcontentlanguage";
            prop.PropertyType = typeof(string);
            value = new PropertyValue();
            value.Property = prop;
            value.Value = resource.DisplayName;
            result.Add(value);

            prop = new Property();
            prop.Name = "getcontentlength";
            prop.PropertyType = typeof(int);
            value = new PropertyValue();
            value.Property = prop;
            value.Value = resource.ContentLength;
            result.Add(value);

            prop = new Property();
            prop.Name = "getcontenttype";
            prop.PropertyType = typeof(string);
            value = new PropertyValue();
            value.Property = prop;
            value.Value = resource.ContentType;
            result.Add(value);

            prop = new Property();
            prop.Name = "getetag";
            prop.PropertyType = typeof(string);
            value = new PropertyValue();
            value.Property = prop;
            value.Value = resource.ETag;
            result.Add(value);

            prop = new Property();
            prop.Name = "getlastmodified";
            prop.PropertyType = typeof(string);
            value = new PropertyValue();
            value.Property = prop;
            value.Value = resource.LastModified;
            result.Add(value);

            prop = new Property();
            prop.Name = "lockdiscovery";
            prop.PropertyType = typeof(int);
            value = new PropertyValue();
            value.Property = prop;
            value.Value = resource.LockDiscovery;
            result.Add(value);

            prop = new Property();
            prop.Name = "resourcetype";
            prop.PropertyType = typeof(int);
            value = new PropertyValue();
            value.Property = prop;
            value.Value = resource.ResourceType;
            result.Add(value);

            prop = new Property();
            prop.Name = "supportedlock";
            prop.PropertyType = typeof(int);
            value = new PropertyValue();
            value.Property = prop;
            value.Value = resource.SupportedLock;
            result.Add(value);

            prop = new Property();
            prop.Name = "lastmodified";
            prop.PropertyType = typeof(DateTime);
            value = new PropertyValue();
            value.Property = prop;
            value.Value = resource.UpdateDate;
            result.Add(value);

            return result;
        }