public static void SaveObject(string persistenceId, string persistenceContext, string objectContent)
        {
            try
            {
                using (var db = new LiteDatabase(__peristenceDbPath))
                {
                    var obj = GetObjects <PersistedObject>(db);
                    var qry = GetQuery(persistenceId, persistenceContext);

                    var po = obj.Find(qry).FirstOrDefault();

                    if (po == null)
                    {
                        po = new PersistedObject
                        {
                            PersistenceId      = persistenceId,
                            PersistenceContext = persistenceContext,
                            Content            = objectContent
                        };

                        obj.Insert(po);
                    }
                    else
                    {
                        po.Content = objectContent;
                        obj.Update(po);
                    }
                }
            }
            catch (Exception ex)
            {
                OP_Logger.LogException(ex);
            }
        }
Example #2
0
 public MoveToolContext(MoveToolContext cloneMe)
     : base(cloneMe)
 {
     this.poLiftedPixelsGuid = cloneMe.poLiftedPixelsGuid;
     this.poLiftedPixels     = cloneMe.poLiftedPixels; // do not clone
     this.liftedPixels       = cloneMe.liftedPixels;   // do not clone
 }
        public SessionManagerHandler(FileHandlerFactoryLocator fileHandlerFactoryLocator, string path)
            : base(fileHandlerFactoryLocator)
        {
            this.persistedSessionDatas = new PersistedObject<Dictionary<ID<ISession, Guid>, SessionData>>(
                path,
                () => new Dictionary<ID<ISession, Guid>, SessionData>(),
                this.Deserialize,
                this.Serialize);

            me = this;

            this.persistedSessionDatas.Read(sessionDatas =>
            {
                this.sessions = new Dictionary<ID<ISession, Guid>, Session>(sessionDatas.Count);

                foreach (var sessionDataKVP in sessionDatas)
                {
                    var sessionId = sessionDataKVP.Key;
                    var sessionData = sessionDataKVP.Value;

                    this.sessions[sessionId] = new Session(
                        this,
                        fileHandlerFactoryLocator,
                        this.persistedSessionDatas,
                        sessionId,
                        sessionData);
                }
            });

            // Clean old sessions every hour or so
            this.cleanOldSessionsTimer = new Timer(CleanOldSessions, null, 0, 6000000);
        }
Example #4
0
 public MoveToolChanges(IEnumerable <KeyValuePair <string, object> > drawingSettingsValues, MoveToolPixelSource pixelSource, ISurface <ColorBgra> bitmapSource, bool leaveCopyBehind, RectDouble baseBounds, Matrix3x2Double baseTransform, Matrix3x2Double deltaTransform, TransformEditingMode editingMode, Matrix3x2Double editTransform, PointDouble?rotationAnchorOffset) : base(drawingSettingsValues)
 {
     if (((pixelSource == MoveToolPixelSource.Bitmap) && (bitmapSource == null)) || ((pixelSource != MoveToolPixelSource.Bitmap) && (bitmapSource != null)))
     {
         ExceptionUtil.ThrowArgumentException($"MoveToolPixelSource.{pixelSource} specified, but bitmapSourcePersistenceKey={this.bitmapSourcePersistenceKey}");
     }
     if (bitmapSource == null)
     {
         this.bitmapSourcePO             = null;
         this.bitmapSourcePersistenceKey = Guid.Empty;
     }
     else
     {
         this.bitmapSourcePO             = new PersistedObject <ISurface <ColorBgra> >(bitmapSource, true);
         this.bitmapSourcePersistenceKey = PersistedObjectLocker.Add <ISurface <ColorBgra> >(this.bitmapSourcePO);
     }
     this.pixelSource          = pixelSource;
     this.leaveCopyBehind      = leaveCopyBehind;
     this.baseBounds           = baseBounds;
     this.baseTransform        = baseTransform;
     this.deltaTransform       = deltaTransform;
     this.editingMode          = editingMode;
     this.editTransform        = editTransform;
     this.rotationAnchorOffset = rotationAnchorOffset;
     this.Initialize();
 }
Example #5
0
        public static object Update(SessionRequest request)
        {
            Attachment attachment = (Attachment)request.Session[new Guid(request.Parameters["attachment"])];

            UpdateAttachment(attachment, request.Body);
            return(PersistedObject.GetNoCreate(attachment, request.Session));
        }
 public NameValuePairsHandler(FileHandlerFactoryLocator fileHandlerFactoryLocator, string path)
     : base(fileHandlerFactoryLocator, path)
 {
     this.persistedPairs = new PersistedObject<Dictionary<string, string>>(
         path,
         () => new Dictionary<string, string>(),
         this.Deserialize,
         this.Serialize);
 }
        public void TestNonExistingObjectTypeReturnsNullOnGet()
        {
            var persistedObject = new PersistedObject {
                Content = "content", Id = "Id"
            };

            PersistanceStore.Save(persistedObject);
            Assert.IsNull(PersistanceStore.Get <PersistedString>("Id"));
        }
Example #8
0
 public virtual void CommitChanges()
 {
     PersistedObject.Update();
     PersistedObjectVersion = PersistedObject.Version;
     LdapcpLogging.Log(
         String.Format("Updated PersistedObject {0} to version {1}", PersistedObject.DisplayName, PersistedObject.Version),
         TraceSeverity.Medium,
         EventSeverity.Information,
         LdapcpLogging.Categories.Configuration);
 }
Example #9
0
 private void Initialize()
 {
     if ((this.baseGeometryPO == null) && (this.baseGeometryPersistenceKey != Guid.Empty))
     {
         this.baseGeometryPO = PersistedObjectLocker.TryGet <GeometryList>(this.baseGeometryPersistenceKey);
         if (this.baseGeometryPO == null)
         {
             throw new InternalErrorException("this.baseGeometry == null");
         }
     }
 }
Example #10
0
 private void Initialize()
 {
     if ((this.bitmapSourcePO == null) && (this.bitmapSourcePersistenceKey != Guid.Empty))
     {
         this.bitmapSourcePO = PersistedObjectLocker.TryGet <ISurface <ColorBgra> >(this.bitmapSourcePersistenceKey);
         if (this.bitmapSourcePO == null)
         {
             throw new PaintDotNet.InternalErrorException("this.bitmapSource == null");
         }
     }
 }
Example #11
0
        public void TestSavingAnExistingObjectReplacesIt()
        {
            var persistedObject = new PersistedObject {
                Content = "content", Id = "Id"
            };

            PersistanceStore.Save(persistedObject);
            persistedObject.Content = "new";
            PersistanceStore.Save(persistedObject);
            var saved = PersistanceStore.Get <PersistedObject>("Id");

            Assert.AreEqual("new", saved.Content);
        }
Example #12
0
        private static List <PersistedObject <Element> > Wrap(List <AutomationElement> searchResults, Session session)
        {
            List <PersistedObject <Element> > result = new List <PersistedObject <Element> >();

            STAHelper.Invoke(
                delegate() {
                foreach (AutomationElement element in searchResults)
                {
                    result.Add(PersistedObject.Get(Element.Create(element, session.Process.Id), session));
                }
            }
                );
            return(result);
        }
 public PaintBucketToolChanges(IEnumerable <KeyValuePair <string, object> > drawingSettingsValues, PointDouble originPoint, FloodMode?floodModeOverride, PaintDotNet.WhichUserColor whichUserColor, GeometryList clippingMask) : base(drawingSettingsValues, originPoint, floodModeOverride)
 {
     this.whichUserColor = whichUserColor;
     if (clippingMask == null)
     {
         this.clippingMaskPO             = null;
         this.clippingMaskPersistenceKey = Guid.Empty;
     }
     else
     {
         this.clippingMaskPO             = new PersistedObject <GeometryList>(clippingMask, true);
         this.clippingMaskPersistenceKey = PersistedObjectLocker.Add <GeometryList>(this.clippingMaskPO);
     }
     this.Initialize();
 }
Example #14
0
 public MagicWandToolChanges(IEnumerable <KeyValuePair <string, object> > drawingSettingsValues, PointDouble originPoint, PaintDotNet.SelectionCombineMode?selectionCombineModeOverride, FloodMode?floodModeOverride, GeometryList baseGeometry) : base(drawingSettingsValues, originPoint, floodModeOverride)
 {
     this.selectionCombineModeOverride = selectionCombineModeOverride;
     if (baseGeometry == null)
     {
         this.baseGeometryPO             = null;
         this.baseGeometryPersistenceKey = Guid.Empty;
     }
     else
     {
         this.baseGeometryPO             = new PersistedObject <GeometryList>(baseGeometry, true);
         this.baseGeometryPersistenceKey = PersistedObjectLocker.Add <GeometryList>(this.baseGeometryPO);
     }
     this.Initialize();
 }
Example #15
0
        public static object GetSelection(ElementRequest request)
        {
            Dictionary <string, object> result = new Dictionary <string, object>();

            result["multiple"] = request.Target.SelectionAllowsMultiple;
            result["required"] = request.Target.SelectionIsRequired;

            List <object> values = new List <object>();

            foreach (Element elt in request.Target.Selection)
            {
                values.Add(PersistedObject.Get(elt, request.Session));
            }
            result["values"] = values;
            return(result);
        }
Example #16
0
        public Session(
			SessionManagerHandler sessionManagerHandler, 
			FileHandlerFactoryLocator fileHandlerFactoryLocator,
			PersistedObject<Dictionary<ID<ISession, Guid>, SessionData>> persistedSessionDatas,
			ID<ISession, Guid> sessionId,
			SessionData sessionData)
        {
            this.sessionManagerHandler = sessionManagerHandler;
            this.fileHandlerFactoryLocator = fileHandlerFactoryLocator;
            this.persistedSessionDatas = persistedSessionDatas;
            this.sessionId = sessionId;

            this.maxAge = sessionData.maxAge;
            this.lastQuery = sessionData.lastQuery;
            this.keepAlive = sessionData.keepAlive;
        }
Example #17
0
        public static object Create(SessionRequest request)
        {
            string extension = null;

            if (request.Body.ContainsKey("name"))
            {
                string name = (string)request.Body["name"];
                if (name != null && name.Contains("."))
                {
                    extension = name.Substring(name.LastIndexOf(".") + 1);
                }
            }
            Attachment attachment = (extension == null) ? new Attachment() : new Attachment(extension);

            UpdateAttachment(attachment, request.Body);
            return(PersistedObject.Get(attachment, request.Session));
        }
Example #18
0
        public void TestDifferentObjectTypeCanBeStored()
        {
            var persistedString = new PersistedString {
                Content = "content", Id = "Id"
            };
            var persistedObject = new PersistedObject {
                Content = "content", Id = "Id"
            };

            PersistanceStore.Save(persistedObject);
            PersistanceStore.Save(persistedString);
            var saved = PersistanceStore.Get <PersistedString>("Id");

            Assert.IsNotNull(saved);
            Assert.AreEqual("Id", saved.Id);
            Assert.AreEqual("content", saved.Content);

            var saved2 = PersistanceStore.Get <PersistedObject>("Id");

            Assert.IsNotNull(saved2);
            Assert.AreEqual("Id", saved2.Id);
            Assert.AreEqual("content", saved2.Content);
        }
Example #19
0
 public static object GetParent(ElementRequest request)
 {
     return(PersistedObject.Get(request.Target.Parent, request.Session));
 }
Example #20
0
 //static ILog log = LogManager.GetLogger<UserHandler>();
 internal UserHandler(PersistedObject<UserData> persistedUserData, PersistedObjectSequence<Notification> persistedNotifications, FileHandlerFactoryLocator fileHandlerFactoryLocator)
     : base(fileHandlerFactoryLocator)
 {
     this.persistedUserData = persistedUserData;
     this.persistedNotifications = persistedNotifications;
 }
Example #21
0
 public static object GetScrollerY(ElementRequest request)
 {
     return(PersistedObject.Get(request.Target.GetScrollAxis(OrientationType.Vertical), request.Session));
 }
Example #22
0
 public static object GetFocused(SessionRequest request)
 {
     return(PersistedObject.Get(Element.Create(AutomationElement.FocusedElement, request.Session.Process.Id), request.Session));
 }
Example #23
0
 public static object GetSelectionContainer(ElementRequest request)
 {
     return(PersistedObject.Get(request.Target.SelectionContainer, request.Session));
 }
Example #24
0
 public MoveToolContext(SerializationInfo info, StreamingContext context)
     : base(info, context)
 {
     this.poLiftedPixelsGuid = (Guid)info.GetValue("poLiftedPixelsGuid", typeof(Guid));
     this.poLiftedPixels = PersistedObjectLocker.Get<MaskedSurface>(this.poLiftedPixelsGuid);
 }
Example #25
0
 protected void BtnReset_Click(object sender, EventArgs e)
 {
     PersistedObject.ResetClaimTypesList();
     PersistedObject.Update();
     Response.Redirect(Request.Url.ToString());
 }
Example #26
0
 public MoveToolContext(MoveToolContext cloneMe)
     : base(cloneMe)
 {
     this.poLiftedPixelsGuid = cloneMe.poLiftedPixelsGuid;
     this.poLiftedPixels = cloneMe.poLiftedPixels; // do not clone
     this.liftedPixels = cloneMe.liftedPixels; // do not clone
 }
 public CallHomeFileHandler(PersistedObject<Dictionary<string, Server>> persistedServers, FileHandlerFactoryLocator fileHandlerFactoryLocator)
     : base(fileHandlerFactoryLocator)
 {
     this.persistedServers = persistedServers;
 }
Example #28
0
 public MoveToolContext(SerializationInfo info, StreamingContext context)
     : base(info, context)
 {
     this.poLiftedPixelsGuid = (Guid)info.GetValue("poLiftedPixelsGuid", typeof(Guid));
     this.poLiftedPixels     = PersistedObjectLocker.Get <MaskedSurface>(this.poLiftedPixelsGuid);
 }
Example #29
0
        /// <summary>
        /// Ensures configuration is valid to proceed
        /// </summary>
        /// <returns></returns>
        public virtual ConfigStatus ValidatePrerequisite()
        {
            if (!this.IsPostBack)
            {
                // DataBind() must be called to bind attributes that are set as "<%# #>"in .aspx
                // But only during initial page load, otherwise it would reset bindings in other controls like SPGridView
                DataBind();
                ViewState.Add("ClaimsProviderName", ClaimsProviderName);
                ViewState.Add("PersistedObjectName", PersistedObjectName);
                ViewState.Add("PersistedObjectID", PersistedObjectID);
            }
            else
            {
                ClaimsProviderName  = ViewState["ClaimsProviderName"].ToString();
                PersistedObjectName = ViewState["PersistedObjectName"].ToString();
                PersistedObjectID   = ViewState["PersistedObjectID"].ToString();
            }

            Status = ConfigStatus.AllGood;
            if (String.IsNullOrEmpty(ClaimsProviderName))
            {
                Status |= ConfigStatus.ClaimsProviderNamePropNotSet;
            }
            if (String.IsNullOrEmpty(PersistedObjectName))
            {
                Status |= ConfigStatus.PersistedObjectNamePropNotSet;
            }
            if (String.IsNullOrEmpty(PersistedObjectID))
            {
                Status |= ConfigStatus.PersistedObjectIDPropNotSet;
            }
            if (Status != ConfigStatus.AllGood)
            {
                ClaimsProviderLogging.Log($"[{ClaimsProviderName}] {MostImportantError}", TraceSeverity.Unexpected, EventSeverity.Error, TraceCategory.Configuration);
                // Should not go further if those requirements are not met
                return(Status);
            }

            if (CurrentTrustedLoginProvider == null)
            {
                CurrentTrustedLoginProvider = LDAPCP.GetSPTrustAssociatedWithCP(this.ClaimsProviderName);
                if (CurrentTrustedLoginProvider == null)
                {
                    Status |= ConfigStatus.NoSPTrustAssociation;
                    return(Status);
                }
            }

            if (PersistedObject == null)
            {
                Status |= ConfigStatus.PersistedObjectNotFound;
            }

            if (Status != ConfigStatus.AllGood)
            {
                ClaimsProviderLogging.Log($"[{ClaimsProviderName}] {MostImportantError}", TraceSeverity.Unexpected, EventSeverity.Error, TraceCategory.Configuration);
                // Should not go further if those requirements are not met
                return(Status);
            }

            PersistedObject.CheckAndCleanConfiguration(CurrentTrustedLoginProvider.Name);
            PersistedObject.ClaimTypes.SPTrust = CurrentTrustedLoginProvider;
            if (IdentityCTConfig == null && Status == ConfigStatus.AllGood)
            {
                IdentityCTConfig = this.IdentityCTConfig = PersistedObject.ClaimTypes.FirstOrDefault(x => String.Equals(CurrentTrustedLoginProvider.IdentityClaimTypeInformation.MappedClaimType, x.ClaimType, StringComparison.InvariantCultureIgnoreCase) && !x.UseMainClaimTypeOfDirectoryObject);
                if (IdentityCTConfig == null)
                {
                    Status |= ConfigStatus.NoIdentityClaimType;
                }
            }
            if (PersistedObjectVersion != PersistedObject.Version)
            {
                Status |= ConfigStatus.PersistedObjectStale;
            }

            if (Status != ConfigStatus.AllGood)
            {
                ClaimsProviderLogging.Log($"[{ClaimsProviderName}] {MostImportantError}", TraceSeverity.Unexpected, EventSeverity.Error, TraceCategory.Configuration);
            }
            return(Status);
        }
Example #30
0
 public virtual void CommitChanges()
 {
     PersistedObject.Update();
     PersistedObjectVersion = PersistedObject.Version;
 }
Example #31
0
 internal UserManagerHandler(PersistedObject<UserManagerData> persistedUserManagerData, FileHandlerFactoryLocator fileHandlerFactoryLocator, int? maxLocalUsers)
     : base(fileHandlerFactoryLocator)
 {
     this.MaxLocalUsers = maxLocalUsers;
     this.persistedUserManagerData = persistedUserManagerData;
 }
Example #32
0
        protected override HistoryMemento OnUndo()
        {
            BitmapHistoryMementoData data = this.Data as BitmapHistoryMementoData;
            BitmapLayer layer             = (BitmapLayer)this.historyWorkspace.Document.Layers[this.layerIndex];

            PdnRegion     region;
            MaskedSurface maskedSurface = null;

            if (this.poMaskedSurfaceRef != Guid.Empty)
            {
                PersistedObject <MaskedSurface> poMS = PersistedObjectLocker.Get <MaskedSurface>(this.poMaskedSurfaceRef);
                maskedSurface = poMS.Object;
                region        = maskedSurface.CreateRegion();
            }
            else if (data.UndoImage == null)
            {
                region = data.SavedRegion;
            }
            else
            {
                region = data.UndoImage.Region;
            }

            BitmapHistoryMemento redo;

            if (this.poUndoMaskedSurfaceRef == Guid.Empty)
            {
                redo = new BitmapHistoryMemento(Name, Image, this.historyWorkspace, this.layerIndex, region);
                redo.poUndoMaskedSurfaceRef = this.poMaskedSurfaceRef;
            }
            else
            {
                redo = new BitmapHistoryMemento(Name, Image, this.historyWorkspace, this.layerIndex, this.poUndoMaskedSurfaceRef);
            }

            PdnRegion simplified = Utility.SimplifyAndInflateRegion(region);

            if (maskedSurface != null)
            {
                maskedSurface.Draw(layer.Surface);
            }
            else if (data.UndoImage == null)
            {
                using (FileStream input = FileSystem.OpenStreamingFile(this.tempFileName, FileAccess.Read))
                {
                    LoadSurfaceRegion(input, layer.Surface, data.SavedRegion);
                }

                data.SavedRegion.Dispose();
                this.tempFileHandle.Dispose();
                this.tempFileHandle = null;
            }
            else
            {
                data.UndoImage.Draw(layer.Surface);
                data.UndoImage.Dispose();
            }

            layer.Invalidate(simplified);
            simplified.Dispose();

            return(redo);
        }