Beispiel #1
0
        public List(TemplateInflator controlTemplateInflator, Func <ICollection <ControlTemplate> > getControlTemplates, IPropertyEngine propertyEngine) : base(propertyEngine)
        {
            RegistrationGuard.RegisterFor <List>(() =>
            {
                ItemTemplateProperty = ItemTemplateProperty = PropertyEngine.RegisterProperty("ItemTemplate", typeof(List), typeof(DataTemplate), new PropertyMetadata());
                SourceProperty       = SourceProperty = PropertyEngine.RegisterProperty("Source", typeof(List), typeof(IObservableCollection <object>), new PropertyMetadata());
            });

            this.controlTemplateInflator = controlTemplateInflator;
            this.getControlTemplates     = getControlTemplates;
            panel = new StackPanel(propertyEngine);
            this.AddChild(panel);

            subscription = GetChangedObservable(SourceProperty).Subscribe(obj =>
            {
                var source = (ISourceList <object>)obj;

                Platform.Current.EventSource.Invalidate();

                source.Connect()
                .OnItemAdded(AddItem)
                .ForEachChange(_ => Platform.Current.EventSource.Invalidate())
                .Subscribe();
            });
        }
        public override ActionResult Save(SocialLinksEditor model)
        {
            var person = Services.Person.Get(model.PersonId, false);

            var social = person.GetPropertyValue <SocialLinks>(true);

            social.Facebook   = model.Facebook;
            social.GooglePlus = model.GooglePlus;
            social.Twitter    = model.Twitter;
            social.LinkedIn   = model.LinkedIn;
            social.YouTube    = model.YouTube;

            var prop = (ExtendedProperty)person.GetProperty(ConverterMapping.ConverterAlias);

            if (prop == null)
            {
                prop = new ExtendedProperty {
                    ConverterAlias = ConverterMapping.ConverterAlias
                };
                prop.SetValue(social);
                person.Properties.Add(prop);
            }
            else
            {
                prop.SetValue(social);
            }

            Services.Person.Save(person, true);

            return(Redirect(model.ReturnUrl));
        }
Beispiel #3
0
        public TextBox(IPropertyEngine propertyEngine) : base(propertyEngine)
        {
            RegistrationGuard.RegisterFor <TextBox>(() =>
            {
                TextWrappingProperty = PropertyEngine.RegisterProperty("TextWrapping", typeof(TextBox), typeof(TextWrapping), new PropertyMetadata {
                    DefaultValue = TextWrapping.NoWrap
                });
                ForegroundProperty = PropertyEngine.RegisterProperty("Foreground", typeof(TextBox), typeof(Brush), new PropertyMetadata {
                    DefaultValue = new Brush(Colors.Black)
                });
                TextProperty = PropertyEngine.RegisterProperty("Text", typeof(TextBox), typeof(string), new PropertyMetadata {
                    DefaultValue = null
                });
                FontFamilyProperty = PropertyEngine.RegisterProperty("FontFamily", typeof(TextBox), typeof(float), new PropertyMetadata {
                    DefaultValue = "Arial"
                });
                FontWeightProperty = PropertyEngine.RegisterProperty("FontWeight", typeof(TextBox), typeof(float), new PropertyMetadata {
                    DefaultValue = FontWeights.Normal
                });
                FontSizeProperty = PropertyEngine.RegisterProperty("FontSize", typeof(TextBox), typeof(float), new PropertyMetadata {
                    DefaultValue = 16F
                });
            });

            NotifyRenderAffectedBy(TextProperty);
            GetChangedObservable(TextProperty).Subscribe(t => Text = (string)t);
            Children.OnChildAdded(AttachToTextBoxView);
        }
Beispiel #4
0
        protected override Task Context()
        {
            var molWeightDimension = A.Fake <IDimension>();

            _extendedPropertyMapper = A.Fake <ExtendedPropertyMapper>();
            var dimensionRepository = A.Fake <IDimensionRepository>();

            A.CallTo(() => dimensionRepository.DimensionByName(Constants.Dimension.MOLECULAR_WEIGHT)).Returns(molWeightDimension);
            sut = new DataInfoMapper(_extendedPropertyMapper, dimensionRepository);

            _extendedPropertySnapshot = new ExtendedProperty();

            _dataInfo = new DataInfo(ColumnOrigins.Observation, AuxiliaryType.GeometricStdDev, "unitName", "category", 2.3)
            {
                LLOQ = 0.4f
            };
            _extendedProperty = new ExtendedProperty <string> {
                Name = "Hello"
            };
            _dataInfo.ExtendedProperties.Add(_extendedProperty);
            A.CallTo(() => molWeightDimension.BaseUnitValueToUnitValue(molWeightDimension.DefaultUnit, _dataInfo.MolWeight.Value)).Returns(5.0);
            A.CallTo(() => molWeightDimension.UnitValueToBaseUnitValue(molWeightDimension.DefaultUnit, 5.0)).Returns(_dataInfo.MolWeight.Value);

            A.CallTo(() => _extendedPropertyMapper.MapToSnapshot(_extendedProperty)).Returns(_extendedPropertySnapshot);
            A.CallTo(() => _extendedPropertyMapper.MapToModel(_extendedPropertySnapshot, A <SnapshotContext> ._)).Returns(_extendedProperty);

            return(Task.FromResult(true));
        }
Beispiel #5
0
    private void CreateNewEvent()
    {
        //Set Event Entry
        Google.GData.Calendar.EventEntry oEventEntry = new Google.GData.Calendar.EventEntry();
        oEventEntry.Title.Text      = "Test Calendar Entry From .Net for testing";
        oEventEntry.Content.Content = "Hurrah!!! I posted my second Google calendar event through .Net";

        //Set Event Location
        Where oEventLocation = new Where();

        oEventLocation.ValueString = "Mumbai";
        oEventEntry.Locations.Add(oEventLocation);

        //Set Event Time
        When oEventTime = new When(new DateTime(2012, 8, 05, 9, 0, 0), new DateTime(2012, 8, 05, 9, 0, 0).AddHours(1));

        oEventEntry.Times.Add(oEventTime);

        //Set Additional Properties
        ExtendedProperty oExtendedProperty = new ExtendedProperty();

        oExtendedProperty.Name  = "SynchronizationID";
        oExtendedProperty.Value = Guid.NewGuid().ToString();
        oEventEntry.ExtensionElements.Add(oExtendedProperty);

        CalendarService oCalendarService = GAuthenticate();
        Uri             oCalendarUri     = new Uri("http://www.google.com/calendar/feeds/[email protected]/private/full");

        //Prevents This Error
        //{"The remote server returned an error: (417) Expectation failed."}
        System.Net.ServicePointManager.Expect100Continue = false;

        //Save Event
        oCalendarService.Insert(oCalendarUri, oEventEntry);
    }
        public static List <ExtendedProperty> CheckUserSettings(CygnusAutomationModel loadConfig, string email, string bulkUserSettingKey)
        {
            List <ExtendedProperty> userSettingsList = new List <ExtendedProperty>();

            SqlConnection cnn = new SqlConnection(loadConfig.DbConnectionString);

            cnn.Open();

            String sql = Queries.GetUpdateUserSettings(email, bulkUserSettingKey);

            SqlCommand    cmd      = new SqlCommand(sql, cnn);
            SqlDataReader dtReader = cmd.ExecuteReader();

            while (dtReader.Read())
            {
                ExtendedProperty usm = new ExtendedProperty();

                usm.IntegerValue = dtReader.GetValue(0).ToString();
                usm.StringValue  = dtReader.GetValue(1).ToString();
                userSettingsList.Add(usm);
            }
            cnn.Close();

            return(userSettingsList);
        }
Beispiel #7
0
        public CExtendedProperty(ExtendedProperty ep)
        {
            InitializeComponent();

            this._ep   = ep;
            this.Load += new EventHandler(CExtendedProperty_Load);
        }
Beispiel #8
0
        public ExtendedProperty CreateExtendedProperty(string name, string description, DataContainer container, ICollection <Constraint> constraints)
        {
            Contract.Requires(!string.IsNullOrWhiteSpace(name));
            Contract.Requires(container != null && container.Id >= 0);

            Contract.Ensures(Contract.Result <ExtendedProperty>() != null && Contract.Result <ExtendedProperty>().Id >= 0);

            ExtendedProperty e = new ExtendedProperty()
            {
                Name          = name,
                Description   = description,
                DataContainer = container,
            };

            //if (constraints != null)
            //    e.Constraints = new List<Constraint>(constraints);

            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository <ExtendedProperty> repo = uow.GetRepository <ExtendedProperty>();
                repo.Put(e);
                uow.Commit();
            }
            return(e);
        }
Beispiel #9
0
 protected override void Context()
 {
     base.Context();
     _onPropertyChangedHandler = A.Fake <PropertyChangedEventHandler>();
     sut = new ExtendedProperty <string>();
     sut.PropertyChanged += _onPropertyChangedHandler;
 }
Beispiel #10
0
 public static ExtendedProperty CreateProperty(string defName, string value, BXC_MasterControlEntities entity, int userId)
 {
     var prop = new ExtendedProperty {User_Id = userId};
     var name = (from n in entity.PropertyNames where n.Name == defName select n).FirstOrDefault();
     if (name != null)
     {
         prop.PropertyNames_Id = name.Id;
     }
     else
     {
         var n = new PropertyName {Name = defName};
         entity.AddObject("PropertyNames", n);
         entity.SaveChanges();
         prop.PropertyNames_Id = n.Id;
     }
     var propValue = (from v in entity.PropertyValues where v.Value == value select v).FirstOrDefault();
     if (propValue != null)
     {
         prop.PropertyValues_Id = propValue.Id;
     }
     else
     {
         var v = new PropertyValue {Value = value};
         entity.AddObject("Propertyvalues", v);
         entity.SaveChanges();
         prop.PropertyValues_Id = v.Id;
     }
     return prop;
 }
Beispiel #11
0
        public TextBoxView(IPropertyEngine propertyEngine) : base(propertyEngine)
        {
            RegistrationGuard.RegisterFor <TextBoxView>(() => TextProperty = PropertyEngine.RegisterProperty("Text",
                                                                                                             typeof(TextBoxView),
                                                                                                             typeof(string), new PropertyMetadata {
                DefaultValue = null
            }));

            var changedObservable = GetChangedObservable(TextProperty);

            Pointer.Down.Subscribe(point =>
            {
                Platform.Current.EventSource.ShowVirtualKeyboard();
                Platform.Current.SetFocusedElement(this);
            });

            Keyboard.KeyInput.Where(Filter).Subscribe(args => AddText(args.Text));
            Keyboard.SpecialKeys.Subscribe(ProcessSpecialKey);
            NotifyRenderAffectedBy(TextProperty);
            Platform.Current.FocusedElement.Select(layout => layout == this)
            .Subscribe(isFocused => IsFocused = isFocused);

            changedSubscription = changedObservable
                                  .Subscribe(o =>
            {
                FormattedText.Text = (string)o;
                EnforceCursorLimits();
                Invalidate();
            });
        }
        public void InsertExtendedPropertyContactsTest()
        {
            Tracing.TraceMsg("Entering InsertExtendedPropertyContactsTest");

            DeleteAllContacts();

            RequestSettings rs = new RequestSettings(this.ApplicationName, this.userName, this.passWord);

            rs.AutoPaging = true;

            FeedQuery query = new FeedQuery();

            query.Uri = new Uri(CreateUri(this.resourcePath + "contactsextendedprop.xml"));



            ContactsRequest cr = new ContactsRequest(rs);

            Feed <Contact> f = cr.Get <Contact>(query);

            Contact newEntry = null;

            foreach (Contact c in f.Entries)
            {
                ExtendedProperty e = c.ExtendedProperties[0];
                Assert.IsTrue(e != null);
                newEntry = c;
            }

            f = cr.GetContacts();

            Contact createdEntry = cr.Insert <Contact>(f, newEntry);

            cr.Delete(createdEntry);
        }
Beispiel #13
0
        /// <summary>
        /// Gets a list of all the calender events in the given calendar
        /// </summary>
        public List <CalendarEvent> GetAllEvents()
        {
            List <CalendarEvent> events        = new List <CalendarEvent>();
            EventQuery           query         = new EventQuery(string.Format(calendarUrl, this.calendarId));
            EventFeed            myResultsFeed = this.calService.Query(query);

            foreach (EventEntry entry in myResultsFeed.Entries)
            {
                string id = "";
                foreach (object obj in entry.ExtensionElements)
                {
                    if (obj is ExtendedProperty)
                    {
                        ExtendedProperty exProp = obj as ExtendedProperty;
                        if (exProp.Name == syncExtendedParameterName)
                        {
                            id = exProp.Value;
                            break;
                        }
                    }
                }

                events.Add(new CalendarEvent(id,
                                             entry.Times[0].StartTime,
                                             entry.Times[0].EndTime,
                                             entry.Locations[0].ValueString,
                                             entry.Title.Text,
                                             entry.Content.Content
                                             ));
            }
            return(events);
        }
        public void SetValueReadOnly()
        {
            SimpleClass      item = new SimpleClass(42, "Orders", DateTime.Now);
            ExtendedProperty prop = new ExtendedProperty(typeof(SimpleClass), "Total");

            prop.PropertyDescriptor.SetValue(item, "Orders: 57");
        }
Beispiel #15
0
        /// <summary>
        /// Creates a google calendar event
        /// </summary>
        public void CreateEvent(CalendarEvent cEvent)
        {
            EventEntry entry = new EventEntry();

            entry.Title.Text      = cEvent.Subject;
            entry.Content.Content = cEvent.Body;

            ExtendedProperty property = new ExtendedProperty();

            property.Name  = syncExtendedParameterName;
            property.Value = cEvent.Id;
            entry.ExtensionElements.Add(property);

            Where eventLocation = new Where();

            eventLocation.ValueString = cEvent.Location;
            entry.Locations.Add(eventLocation);

            When eventTime = new When(cEvent.StartDate, cEvent.EndDate);

            entry.Times.Add(eventTime);

            Uri postUri = new Uri(string.Format(calendarUrl, this.calendarId));

            AtomEntry insertedEntry = this.calService.Insert(postUri, entry);
        }
Beispiel #16
0
        internal static void EncodeToStream(ExtendedProperty attribute, Stream stream)
        {
            VarEnum interopTypeInfo;
            object  data = attribute.Value;

            // NTRAID#T2-23063-2003/12/10-Microsoft: CODEQUALITY: Find better way to discover which properties should be persistable
            if (attribute.Id == KnownIds.DrawingFlags)
            {
                interopTypeInfo = VarEnum.VT_I4;
            }
            else if (attribute.Id == KnownIds.StylusTip)
            {
                interopTypeInfo = VarEnum.VT_I4;
            }
            else
            {
                // Find the type of the object if it's embedded in the stream
                if (UsesEmbeddedTypeInformation(attribute.Id))
                {
                    interopTypeInfo = SerializationHelper.ConvertToVarEnum(attribute.Value.GetType(), true);
                }
                else // Otherwise treat this as byte array
                {
                    interopTypeInfo = (VarEnum.VT_ARRAY | VarEnum.VT_UI1);
                }
            }
            EncodeAttribute(attribute.Id, data, interopTypeInfo, stream);
        }
Beispiel #17
0
        public void InterceptExtendedProperties()
        {
            Engine c = new Engine("InterceptExtendedProperties");

            SignatureAspect aspect = new SignatureAspect("PropertyAdder", typeof(Foo), new Type[] { }, new IPointcut[] { });

            aspect.Pointcuts.Add(new SignaturePointcut("get_MyIntProperty", new IncreaseReturnValueInterceptor()));

            TypeExtender extender = new TypeExtender();

            ExtendedProperty property1 = new ExtendedProperty();

            property1.Name      = "MyIntProperty";
            property1.FieldName = "_MyIntProperty";
            property1.Type      = typeof(int);
            extender.Members.Add(property1);

            aspect.TypeExtenders.Add(extender);

            c.Configuration.Aspects.Add(aspect);
            Foo proxy = (Foo)c.CreateProxy(typeof(Foo));

            PropertyInfo property1Info = proxy.GetType().GetProperty("MyIntProperty");

            Assert.IsNotNull(property1, "Property1 was not emitted");


            property1Info.SetValue(proxy, 123, null);
            int resInt = (int)property1Info.GetValue(proxy, null);

            Assert.IsTrue(resInt == 124, "Property1 Was not intercepted");
        }
Beispiel #18
0
        /// <summary>
        /// Adds if not exists or updates if exists an extended property for database object
        /// </summary>
        /// <param name="databaseFactory">Instance of <see cref="SqlServerDatabaseFactory"/> class</param>
        /// <param name="view">Instance of <see cref="View"/> class</param>
        /// <param name="column">Instance of <see cref="Column"/> class</param>
        /// <param name="name">Extended property name</param>
        /// <param name="value">Extended property value</param>
        public static void AddOrUpdateExtendedProperty(this SqlServerDatabaseFactory databaseFactory, IView view, Column column, string name, string value)
        {
            var model = new ExtendedProperty(name, "schema", view.Schema, "view", view.Name, "column", column.Name)
            {
                Value = value
            };

            using (var connection = databaseFactory.GetConnection())
            {
                connection.Open();

                var repository = new ExtendedPropertyRepository(connection);

                var extendedProperty = repository.GetExtendedProperties(model).FirstOrDefault();

                if (extendedProperty == null)
                {
                    repository.AddExtendedProperty(model);
                }
                else
                {
                    repository.UpdateExtendedProperty(model);
                }

                column.Description = value;
            }
        }
Beispiel #19
0
        private bool UpdateExtendedProperties(ExtendedPropertyCollection properties, SqlExtendedPropertyContainer container)
        {
            bool             DoAlter = false;
            ExtendedProperty prop    = null;

            foreach (string key in container.Properties.Keys)
            {
                if (properties.Contains(key))
                {
                    prop = properties[key];
                }
                else
                {
                    prop = new ExtendedProperty(properties.Parent, key);
                    properties.Add(prop);
                    DoAlter = true;
                }
                prop.Value = container.Properties[key];
                prop.Alter();
            }

            foreach (ExtendedProperty prop2 in properties)
            {
                if (!container.Properties.ContainsKey(prop2.Name))
                {
                    prop2.MarkForDrop(true);
                    DoAlter = true;
                }
            }
            return(DoAlter);
        }
    private void setExtendedProperty(string KeyName, object Value)
    {
        // Grab the property to set
        ExtendedProperty property = this.getExtendedProperty(KeyName);

        // Set the value
        property.Value = Value;
    }
 protected override void CreateExtendedProperty()
 {
     _extendedProperty = new ExtendedProperty <string> {
         Description = "Description", FullName = "FullName", Name = "FirstName", ReadOnly = true, Value = "Value"
     };
     _extendedProperty.AddToListOfValues("Option 1");
     _extendedProperty.AddToListOfValues("Option 2");
 }
 protected override void CreateExtendedProperty()
 {
     _extendedProperty = new ExtendedProperty <double> {
         Description = "Description", FullName = "FullName", Name = "FirstName", ReadOnly = true, Value = 5.5
     };
     _extendedProperty.AddToListOfValues(6.5);
     _extendedProperty.AddToListOfValues(7.5);
 }
 protected override void CreateExtendedProperty()
 {
     _extendedProperty = new ExtendedProperty <bool> {
         Description = "Description", FullName = "FullName", Name = "FirstName", ReadOnly = false, Value = true
     };
     _extendedProperty.AddToListOfValues(true);
     _extendedProperty.AddToListOfValues(false);
 }
 protected override void CreateSnapshot()
 {
     _snapshot = new ExtendedProperty {
         Description = "Description", ReadOnly = true, FullName = "Full Name", ListOfValues = new List <object> {
             4.5, 6.5
         }, Name = "Name", Value = 5.5
     };
 }
Beispiel #25
0
        private BehaviorSubject <object> GetSubject(ExtendedProperty property, object instance)
        {
            var propertyEntry = GetEntry(property, instance);
            var subject       = values.GetCreate(propertyEntry,
                                                 () => new BehaviorSubject <object>(getDefaultValue(property, instance)));

            return(subject);
        }
Beispiel #26
0
 public StandardEngineTests()
 {
     sut      = new ExtendedPropertyEngine();
     property = sut.RegisterProperty("IntProperty", typeof(Grid), typeof(int), new PropertyMetadata()
     {
         DefaultValue = DefaultValue
     });
 }
Beispiel #27
0
        protected override void Context()
        {
            base.Context();
            var data = new ExtendedProperty <string>();

            data.ValueAsObject = "thisdata";
            sut.ExtendedProperties.Add("thisname", data);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="PropertyValueConverterBase{TValue}"/> class.
 /// </summary>
 /// <param name="prop">
 /// The prop.
 /// </param>
 /// <exception cref="ArgumentNullException">
 /// Throws an exception if the property is null
 /// </exception>
 protected PropertyValueConverterBase(ExtendedProperty prop)
 {
     if (prop == null)
     {
         throw new ArgumentNullException(nameof(prop));
     }
     Property = prop;
 }
Beispiel #29
0
 protected override void Context()
 {
     base.Context();
     sut = new ExtendedProperty <string>();
     sut.AddToListOfValues("new");
     sut.AddToListOfValues("string");
     sut.AddToListOfValues("value");
     sut.Value = "new";
 }
        public void GetValueWrongTypeValueType()
        {
            var item = new SimpleClass(42, "Orders", DateTime.Now);
            var prop = new ExtendedProperty(typeof(SimpleClass), "Total", typeof(DateTime), true, null);

            prop.GetValue += delegate(object sender, ExtendedPropertyEventArgs args) { args.Value = 42; };

            var propValue = prop.PropertyDescriptor.GetValue(item);
        }
		public void ConstructDefaultValue()
		{
			ExtendedProperty prop = new ExtendedProperty(typeof(SimpleClass), "Total", typeof(int), true, 42);
			Assert.AreEqual(42, prop.Default);
			Assert.AreEqual("Total", prop.Name);
			Assert.IsNotNull(prop.PropertyDescriptor);
			Assert.AreEqual(typeof(int), prop.PropertyType);
			Assert.IsFalse(prop.IsReadOnly);
		}
		public void Construct()
		{
			ExtendedProperty prop = new ExtendedProperty(typeof(SimpleClass), "Total");
			Assert.IsNull(prop.Default);
			Assert.AreEqual("Total", prop.Name);
			Assert.IsNotNull(prop.PropertyDescriptor);
			Assert.AreEqual(typeof(string), prop.PropertyType);
			Assert.IsTrue(prop.IsReadOnly);
		}
        public void Create()
        {
            BrokerService    brokerService = null;
            ExtendedProperty prop          = null;

            if (!this.ServiceBroker.Services.Contains(this.FullName))
            {
                // Create initiator service
                brokerService           = new BrokerService(this.ServiceBroker, this.FullName);
                brokerService.QueueName = this.QueueName;
                brokerService.Owner     = this.ServiceOwnerName;

                foreach (object item in this.ContractNames)
                {
                    ServiceContractMapping brokerServiceContract
                        = new ServiceContractMapping(brokerService, item.ToString());
                    brokerService.ServiceContractMappings.Add(brokerServiceContract);
                }

                if (!String.IsNullOrEmpty(this.ServiceOwnerName))
                {
                    CreateUser();
                }

                //Create Certificate if EnableRemoteServiceBinding = true and AllowAnonymous = false
                if (m_EnableRemoteServiceBinding &&
                    !String.IsNullOrEmpty(this.ServiceOwnerName) && !this.AllowAnonymous)
                {
                    prop = new ExtendedProperty(brokerService,
                                                "CertificateName", this.Certificate.Name);

                    this.Certificate.Owner = this.ServiceOwnerName;
                    this.Certificate.Create();
                }

                //Create ReportServiceBinding
                if (m_EnableRemoteServiceBinding && !String.IsNullOrEmpty(this.ServiceOwnerName))
                {
                    this.CreateRemoteServiceBinding();
                }

                //Grant Receive
                if (this.GrantReceive)
                {
                    CreateGrantReceive();
                }

                brokerService.Create();

                //Create property last
                if (prop != null)
                {
                    prop.Create();
                }
            }
        }
 public static void SetExtendedPropertyValue(this Database db, string epName, string value)
 {
     var ep = db.ExtendedProperties[epName];
     if (ep == null)
     {
         ep = new ExtendedProperty(db, epName);
         ep.Value = value;
         ep.Create();
     }
     else
     {
         ep.Value = value;
         ep.Alter();
     }
 }
Beispiel #35
0
		static int Main(string[] args)
		{
			try
			{
				if (args.Contains("/runondbupdated"))
				{
					var server = new Server(Common.Properties.SqlServer);
					var database = server.Databases[Common.Properties.SqlDatabase];
					var dbVersion = database.ExtendedProperties[DatabaseVersionExtendedPropertyName];
					if (dbVersion == null) throw new Exception("DatabaseVersion was null! Probably needs ScriptRunner to execute against it");

					var extendedPropertyName = "DatabaseVersion(" + args[0] + "|" + Hash(args[1]) + ")";

					var toolVersion = database.ExtendedProperties[extendedPropertyName];
					var toolVersionParts = (toolVersion == null ? "0|" + DateTime.MinValue + "|" + DateTime.MinValue + "|" + "noscript" : (string) toolVersion.Value).Split('|');
					var dbVersionParts = ((string) dbVersion.Value).Split('|');
					if (int.Parse(toolVersionParts[0]) < int.Parse(dbVersionParts[0]) || DateTime.Parse(toolVersionParts[1]) < DateTime.Parse(dbVersionParts[1]))
					{
						Console.WriteLine("Db version changed. Running tool.");
						int returnValue = RunProcess(args);
						if (returnValue != 0)
						{
							return returnValue;
						}
						if (database.ExtendedProperties[extendedPropertyName] == null)
						{
							var ep = new ExtendedProperty() {Parent = database, Name = extendedPropertyName, Value = database.ExtendedProperties[DatabaseVersionExtendedPropertyName].Value};
							ep.Create();
						}
						else
						{
							database.ExtendedProperties[extendedPropertyName].Value = database.ExtendedProperties[DatabaseVersionExtendedPropertyName].Value;
							database.ExtendedProperties[extendedPropertyName].Alter();
						}
					}
					return 0;
				}
				else
				{
					return RunProcess(args);
				}
			}catch(Exception ex)
			{
				Console.WriteLine(ex.ToString());
				return 1;
			}
		}
		public void GetValue()
		{
			SimpleClass item = new SimpleClass(42, "Orders", DateTime.Now);
			ExtendedProperty prop = new ExtendedProperty(typeof(SimpleClass), "Total");

			int callbacks = 0;
			prop.GetValue += delegate(object sender, ExtendedPropertyEventArgs args)
			{
				callbacks++;
				Assert.AreEqual("Total", args.PropertyName);
				Assert.AreSame(item, args.Target);
				Assert.AreEqual(null, args.Value);

				args.Value = string.Format("{0}: {1}", ((SimpleClass)args.Target).StringValue, ((SimpleClass)args.Target).IntegerValue);
			};

			object propValue = prop.PropertyDescriptor.GetValue(item);

			Assert.AreEqual(1, callbacks);
			Assert.IsNotNull(propValue);
			Assert.AreEqual(typeof(string), propValue.GetType());
			Assert.AreEqual("Orders: 42", propValue);
		}
Beispiel #37
0
        private void ProcessVersion(XmlElement xmlElement)
        {
            // Drop version property if present
            if (database.ExtendedProperties.Contains(Constants.KeyVersion))
            {
                database.ExtendedProperties[Constants.KeyVersion].Drop();
            }

            ExtendedProperty exp = new ExtendedProperty(database, Constants.KeyVersion);
            exp.Value = xmlElement.InnerText;
            database.ExtendedProperties.Add(exp);
            exp.Create();
        }
Beispiel #38
0
        private void AddExtendedProperty(string name, string strValue, IExtendedProperties smoObject)
        {
            name = Constants.SchemaMeta + "." + name;

            object value = ParseString(strValue);

            ExtendedProperty exp;

            if (smoObject.ExtendedProperties.Contains(name))
            {
                exp = smoObject.ExtendedProperties[name];
                exp.Value = value;
                exp.Alter();
            }
            else
            {
                exp = new ExtendedProperty((SqlSmoObject)smoObject, name, value);
                smoObject.ExtendedProperties.Add(exp);
                exp.Create();
            }
        }
		public void SetValue()
		{
			SimpleClass item = new SimpleClass(42, "Orders", DateTime.Now);
			ExtendedProperty prop = new ExtendedProperty(typeof(SimpleClass), "Total", typeof(string), true, null);

			int callbacks = 0;
			prop.SetValue += delegate(object sender, ExtendedPropertyEventArgs args)
			{
				callbacks++;
				Assert.AreEqual("Total", args.PropertyName);
				Assert.AreSame(item, args.Target);
				Assert.IsNotNull(args.Value);
				Assert.AreEqual(typeof(string), args.Value.GetType());
				Assert.AreEqual("Orders: 57", args.Value);
			};

			prop.PropertyDescriptor.SetValue(item, "Orders: 57");

			Assert.AreEqual(1, callbacks);
		}
		public void SetValueReadOnly()
		{
			SimpleClass item = new SimpleClass(42, "Orders", DateTime.Now);
			ExtendedProperty prop = new ExtendedProperty(typeof(SimpleClass), "Total");
			prop.PropertyDescriptor.SetValue(item, "Orders: 57");
		}
        public void Create()
        {
            BrokerService brokerService = null;
            ExtendedProperty prop = null;
            if (!this.ServiceBroker.Services.Contains(this.FullName))
            {
                // Create initiator service
                brokerService = new BrokerService(this.ServiceBroker, this.FullName);
                brokerService.QueueName = this.QueueName;
                brokerService.Owner = this.ServiceOwnerName;

                foreach (object item in this.ContractNames)
                {
                    ServiceContractMapping brokerServiceContract
                        = new ServiceContractMapping(brokerService, item.ToString());
                    brokerService.ServiceContractMappings.Add(brokerServiceContract);
                }

                if (!String.IsNullOrEmpty(this.ServiceOwnerName))
                {
                    CreateUser();
                }

                //Create Certificate if EnableRemoteServiceBinding = true and AllowAnonymous = false
                if (m_EnableRemoteServiceBinding
                    && !String.IsNullOrEmpty(this.ServiceOwnerName) && !this.AllowAnonymous)
                {
                    prop = new ExtendedProperty(brokerService, 
                        "CertificateName", this.Certificate.Name);
                    
                    this.Certificate.Owner = this.ServiceOwnerName;
                    this.Certificate.Create();
                }

                //Create ReportServiceBinding
                if (m_EnableRemoteServiceBinding && !String.IsNullOrEmpty(this.ServiceOwnerName))
                {
                    this.CreateRemoteServiceBinding();
                }

                //Grant Receive
                if (this.GrantReceive)
                {
                    CreateGrantReceive();
                }

                brokerService.Create();

                //Create property last
                if (prop != null)
                    prop.Create();
            }
        }
		public void GetValueWrongTypeReferenceType()
		{
			SimpleClass item = new SimpleClass(42, "Orders", DateTime.Now);
			ExtendedProperty prop = new ExtendedProperty(typeof(SimpleClass), "Total", typeof(string), true, null);

			prop.GetValue += delegate(object sender, ExtendedPropertyEventArgs args)
			{
				args.Value = 42;
			};

			object propValue = prop.PropertyDescriptor.GetValue(item);
		}
        public void Create() 
        {
            ExtendedProperty prop;

            //Drop the properties
            this.Drop();

            IDictionaryEnumerator enumerator = m_Properties.GetEnumerator();
            while (enumerator.MoveNext())
            {
                if (!this.ServiceBroker.Parent.ExtendedProperties.Contains(enumerator.Key.ToString()))
                {
                    prop = new ExtendedProperty(this.ServiceBroker.Parent,
                       enumerator.Key.ToString(), enumerator.Value.ToString());
                    prop.Create();
                }
            }    
        }
		public void GetValueNullNullableValueType()
		{
			SimpleClass item = new SimpleClass(42, "Orders", DateTime.Now);
			ExtendedProperty prop = new ExtendedProperty(typeof(SimpleClass), "Total", typeof(int?), true, null);

			prop.GetValue += delegate(object sender, ExtendedPropertyEventArgs args)
			{
				args.Value = null;
			};

			object propValue = prop.PropertyDescriptor.GetValue(item);

			Assert.IsNull(propValue);
		}
		public void GetValueNullReferenceType()
		{
			SimpleClass item = new SimpleClass(42, "Orders", DateTime.Now);
			ExtendedProperty prop = new ExtendedProperty(typeof(SimpleClass), "Total", typeof(string), true, null);

			int callbacks = 0;
			prop.GetValue += delegate(object sender, ExtendedPropertyEventArgs args)
			{
				callbacks++;
				args.Value = null;
			};

			object propValue = prop.PropertyDescriptor.GetValue(item);

			Assert.IsNull(propValue);
		}
Beispiel #46
0
        /// <summary>
        /// Sets the schema version in the database.
        /// </summary>
        /// <param name="version">The version.</param>
        /// <returns></returns>
        public override bool SetVersion(string databaseName, Domain.Values.Version version)
        {
            try
            {
                if (_server.Databases[databaseName].ExtendedProperties.Contains("SCHEMA_VERSION"))
                {
                    var extendedProperty = _server.Databases[databaseName].ExtendedProperties["SCHEMA_VERSION"];
                    extendedProperty.Value = version.ToString();
                    extendedProperty.Alter();
                }
                else
                {
                    var extendedProperty = new ExtendedProperty(_server.Databases[databaseName], "SCHEMA_VERSION", version.ToString());
                    extendedProperty.Create();

                    _server.Databases[databaseName].Alter();
                }
            }
            catch (ExecutionFailureException efeEx)
            {
                log.Error("An Exception occurred. See the debug information that follows.", efeEx);
                return false;
            }
            catch (SmoException smoEx)
            {
                log.Error("An Exception occurred. See the debug information that follows.", smoEx);
                return false;
            }

            return true;
        }
        public void Alter()
        {
            BrokerService brokerService;
            ExtendedProperty prop = null;

            if (this.ServiceBroker.Services.Contains(this.FullName))
            {
                brokerService = this.ServiceBroker.Services[this.FullName];

                brokerService.QueueName = this.QueueName;
                
                //Drop Contracts that user removed
                foreach (ServiceContractMapping map in brokerService.ServiceContractMappings)
                {
                    if (!this.ContractNames.Contains(map.Name))
                    {
                        if (map.State != SqlSmoState.ToBeDropped)
                        {
                            map.MarkForDrop(true);
                        }
                    }
                }
                //Add Contracts that user added
                foreach (string name in this.ContractNames)
                {
                    if (!brokerService.ServiceContractMappings.Contains(name))
                    {
                        ServiceContractMapping brokerServiceContract
                        = new ServiceContractMapping(brokerService, name);
                        brokerService.ServiceContractMappings.Add(brokerServiceContract);
                    }
                
                }

                brokerService.Alter();

                //Drop RemoteServiceBinding and Certificate
                if (!m_EnableRemoteServiceBinding)
                {

                    if (this.ServiceBroker.RemoteServiceBindings.Contains(this.BindingFullName))
                    {
                        RemoteServiceBinding binding = this.ServiceBroker.
                            RemoteServiceBindings[this.BindingFullName];
                        binding.Drop();
                    }

                    this.DropCertificate();
                    //Drop extended property
                    if (brokerService.ExtendedProperties.Contains("CertificateName"))
                        brokerService.ExtendedProperties["CertificateName"].Drop();
                }

                //Change RemoteServiceBinding
                if (m_EnableRemoteServiceBinding && !String.IsNullOrEmpty(this.ServiceOwnerName))
                {
                    if (this.ServiceBroker.RemoteServiceBindings.Contains(this.BindingFullName))
                    {
                        RemoteServiceBinding binding = this.ServiceBroker.
                            RemoteServiceBindings[this.BindingFullName];
                        binding.IsAnonymous = this.AllowAnonymous;
                        //Can't change service owner binding.Owner = this.ServiceOwnerName;

                        binding.Alter();
                    }
                }

                //Create Certificate if EnableRemoteServiceBinding = true and AllowAnonymous = false
                if (m_EnableRemoteServiceBinding
                    && !String.IsNullOrEmpty(this.ServiceOwnerName) && !this.AllowAnonymous)
                {
                    if (!brokerService.ExtendedProperties.Contains("CertificateName"))
                        prop = new ExtendedProperty(brokerService,
                            "CertificateName", this.Certificate.Name);

                    this.Certificate.Owner = this.ServiceOwnerName;
                    this.Certificate.Create();
                }

                //Create ReportServiceBinding
                if (m_EnableRemoteServiceBinding && !String.IsNullOrEmpty(this.ServiceOwnerName))
                {
                    this.CreateRemoteServiceBinding();
                }

                if (this.GrantReceive)
                {
                    CreateGrantReceive();
                }

                //Create property last
                if (prop != null)
                    prop.Create();
            }
        }
Beispiel #48
0
        private bool UpdateExtendedProperties(ExtendedPropertyCollection properties, SqlExtendedPropertyContainer container)
        {
            bool DoAlter = false;
            ExtendedProperty prop = null;
            foreach (string key in container.Properties.Keys)
            {
                if (properties.Contains(key))
                {
                    prop = properties[key];
                }
                else
                {
                    prop = new ExtendedProperty(properties.Parent, key);
                    properties.Add(prop);
                    DoAlter = true;
                }
                prop.Value = container.Properties[key];
                prop.Alter();
            }

            foreach (ExtendedProperty prop2 in properties)
            {
                if (!container.Properties.ContainsKey(prop2.Name))
                {
                    prop2.MarkForDrop(true);
                    DoAlter = true;
                }
            }
            return DoAlter;

        }
 public ExtendedPropertyNodeFactory( ExtendedProperty property, ExtendedProperties collection )
 {
     _property = property;
     _collection = collection;
 }