示例#1
0
        private void Initialize()
        {
            _Template = new Lazy <AFElementTemplate>(() =>
            {
                var templateName = _EventFrameLoader.GetEventFrameTemplate(_Connection, this._ID);
                return(AFElementTemplate.FindByName(templateName));
            }, System.Threading.LazyThreadSafetyMode.ExecutionAndPublication);

            _EventFrames = new Lazy <ObservableCollection <AFEventFrame> >(() => {
                List <AFEventFrame> frames = _EventFrameLoader.GetEventFrames(_Connection, _ID).ToList();

                ObservableCollection <AFEventFrame> obsList = new ObservableCollection <AFEventFrame>(frames);
                obsList.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(ChildrenChanged);

                return(obsList);
            }, System.Threading.LazyThreadSafetyMode.ExecutionAndPublication);

            _Attributes = new Lazy <ObservableCollection <AFAttribute> >(() => {
                var attrs = _EventFrameLoader.GetAttributes(_Connection, this._ID, "*", "*", "*", "*", false, "Name", "Ascending", 0, false, false, 1000);
                ObservableCollection <AFAttribute> obsList = new ObservableCollection <AFAttribute>();

                foreach (var attribute in attrs)
                {
                    obsList.Add(AFAttribute.Find(_Connection, attribute.ID));
                }

                obsList.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(AttributesChanged);

                return(obsList);
            }, System.Threading.LazyThreadSafetyMode.ExecutionAndPublication);
        }
示例#2
0
        public override void CheckIn()
        {
            if (IsDirty && !IsDeleted)
            {
                _EventFrameController.Update(_Connection, this);

                if (_EventFrames != null)
                {
                    foreach (AFEventFrame frame in _EventFrames.Where(x => x.IsNew || x.IsDeleted))
                    {
                        if (frame.IsNew)
                        {
                            _EventFrameController.CreateEventFrame(_Connection, WebID, frame);
                        }
                        else if (frame.IsDeleted)
                        {
                            frame.Delete();
                            frame.CheckIn();
                        }
                    }
                }

                if (_Attributes != null)
                {
                    foreach (AFAttribute attr in _Attributes.Where(x => x.IsDeleted))
                    {
                        AFAttribute.Delete(_Connection, attr.WebID);
                    }
                }

                ResetState();
            }
        }
示例#3
0
        /// <summary>
        /// Builds loader object and sets all callbacks for lazy loading
        /// </summary>
        private void Initialize()
        {
            //Initialize Category List

            _Categories = new Lazy <ObservableCollection <string> >(() => {
                return(new ObservableCollection <string>(_ElementLoader.GetCategories(_Connection, _ID)));
            }, System.Threading.LazyThreadSafetyMode.ExecutionAndPublication);

            //Initialize Template Loader
            _Template = new Lazy <AFElementTemplate>(() =>
            {
                string templateName = _ElementLoader.GetElementTemplate(_Connection, this._ID);
                return(AFElementTemplate.Find(_Connection, templateName));
            }, System.Threading.LazyThreadSafetyMode.ExecutionAndPublication);

            //Initialize Parent Loader
            string parentPath = Path.Substring(0, Path.LastIndexOf('\\'));

            _Parent = new Lazy <AFElement>(() =>
            {
                return(_ElementLoader.FindByPath(_Connection, parentPath));
            }, System.Threading.LazyThreadSafetyMode.ExecutionAndPublication);

            //Initialize Attributes Loader
            _Attributes = new Lazy <ObservableCollection <AFAttribute> >(() =>
            {
                List <LazyObjects.AFAttribute> resultList  = _ElementLoader.GetAttributes(_Connection, this.ID).ToList();
                ObservableCollection <AFAttribute> obsList = new ObservableCollection <AFAttribute>();

                foreach (var attr in resultList)
                {
                    obsList.Add(AFAttribute.Find(_Connection, attr.ID));
                }

                obsList.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(AttributesChanged);
                return(obsList);
            }, System.Threading.LazyThreadSafetyMode.ExecutionAndPublication);

            //Initialize Children Loader
            _Children = new Lazy <ObservableCollection <AFElement> >(() =>
            {
                List <LazyObjects.AFElement> resultList  = _ElementLoader.GetElements(_Connection, this.ID).ToList();
                ObservableCollection <AFElement> obsList = new ObservableCollection <AFElement>(resultList);
                obsList.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(ChildrenChanged);
                return(obsList);
            }, System.Threading.LazyThreadSafetyMode.ExecutionAndPublication);
        }
示例#4
0
 private void AttributesChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
 {
     if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
     {
         AFAttribute.Create(_Connection, this._ID, (AFAttribute)sender);
     }
     else if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Remove)
     {
         AFAttribute obj = (AFAttribute)sender;
         AFAttribute.Delete(_Connection, obj.ID);
     }
     else if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Replace)
     {
         throw new NotImplementedException("Replace is not supported by LazyPI.");
     }
     else if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Reset)
     {
         throw new NotImplementedException("Reset is not supported by LazyPI.");
     }
     else if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Move)
     {
         throw new NotImplementedException("Move is not supported by LazyPI.");
     }
 }
示例#5
0
 /// <summary>
 /// Creates element using the partial Attribute provided.
 /// </summary>
 /// <param name="ElementID">The element that will hold the attribute.</param>
 /// <param name="Attr">The partial attribute holding information to create attribute.</param>
 /// <returns>Returns true if creation completes properly.</returns>
 /// <remarks>It is expected that the attribute will not have ID and Path</remarks>
 public static bool Create(LazyPI.Common.Connection Connection, string ElementID, AFAttribute Attr)
 {
     return _AttrLoader.Create(Connection, ElementID, Attr);
 }
示例#6
0
 /// <summary>
 /// Creates element using the partial Attribute provided.
 /// </summary>
 /// <param name="ElementID">The element that will hold the attribute.</param>
 /// <param name="Attr">The partial attribute holding information to create attribute.</param>
 /// <returns>Returns true if creation completes properly.</returns>
 /// <remarks>It is expected that the attribute will not have ID and Path</remarks>
 public static bool Create(LazyPI.Common.Connection Connection, string ElementID, AFAttribute Attr)
 {
     return(_AttrLoader.Create(Connection, ElementID, Attr));
 }
        public bool CreateAttribute(LazyPI.Common.Connection Connection, string FrameID, LazyObjects.AFAttribute attribute)
        {
            WebAPIConnection webConnection = (WebAPIConnection)Connection;
            var request = new RestRequest("/eventframes/{webId}/attributes", Method.POST);

            request.AddUrlSegment("webId", FrameID);
            request.AddBody(attribute);

            var statusCode = webConnection.Client.Execute(request).StatusCode;

            return((int)statusCode == 201 ? true : false);
        }
示例#8
0
 public static void Create(Connection Connection, string ElementID, AFAttribute Attr)
 {
     GetController(Connection).Create(Connection, ElementID, Attr);
 }
示例#9
0
        public bool CreateAttribute(LazyPI.Common.Connection Connection, string ParentID, LazyObjects.AFAttribute Attr)
        {
            WebAPIConnection webConnection = (WebAPIConnection)Connection;
            var request = new RestRequest("/elements/{webId}/attributes", Method.POST);

            request.AddUrlSegment("webId", ParentID);
            request.AddBody(Attr);

            var statusCode = webConnection.Client.Execute(request).StatusCode;

            return((int)statusCode == 201);
        }