Пример #1
0
        public async Task DeleteDocumentAsync(int dataProviderId, string catalogNumber)
        {
            // todo - check if we delete an already deleted document, then return
            var currentDocument = await GetDocumentAsync(dataProviderId, catalogNumber);

            var    previousVersionNumber = currentDocument.Version;
            JToken diff = _jdp.Diff(JToken.FromObject(currentDocument.Current), JToken.Parse("{}"));

            currentDocument.Current = null;
            VersionHistory versionHistory = new VersionHistory(diff.ToString(Formatting.None))
            {
                Version   = previousVersionNumber,
                UtcDate   = currentDocument.UtcDate,
                IsDeleted = true,
                Type      = currentDocument.Type
            };

            currentDocument.UtcDate = DateTime.UtcNow;
            currentDocument.Prev.Add(versionHistory);
            currentDocument.Version   = previousVersionNumber + 1;
            currentDocument.IsDeleted = true;
            var result = Collection.ReplaceOne(
                item => item.DataProviderId == dataProviderId && item.CatalogNumber == catalogNumber,
                currentDocument);
        }
Пример #2
0
        private bool UpdateVersionedObservationObject(VersionedDocumentObservation <T> versionedObservation, T updatedObservation)
        {
            var    previousVersionNumber = versionedObservation.Version;
            JToken jtokenCurrentDoc      = versionedObservation.Current == null
                ? JToken.Parse("{}")
                : JToken.FromObject(versionedObservation.Current);

            JToken diff = _jdp.Diff(jtokenCurrentDoc, JToken.FromObject(updatedObservation));

            if (diff == null)
            {
                return(false);              // no change
            }
            versionedObservation.Current = updatedObservation;
            VersionHistory versionHistory = new VersionHistory(diff.ToString(Formatting.None))
            {
                Version = previousVersionNumber,
                UtcDate = versionedObservation.UtcDate,
                Type    = versionedObservation.Type,
            };

            versionedObservation.UtcDate = DateTime.UtcNow;
            versionedObservation.Prev.Add(versionHistory);
            versionedObservation.Version   = previousVersionNumber + 1;
            versionedObservation.IsDeleted = false;
            versionedObservation.Type      = updatedObservation.GetType().ToString();
            return(true);
        }
Пример #3
0
 public void Config(VersionHistoryRegistry registry)
 {
     registry.AddWithAutoKey(VersionHistory.Create(VersionCategory, "0.1.0", new DateTime(2018, 04, 11), "初始版本"));
     registry.AddWithAutoKey(VersionHistory.Create(VersionCategory, "0.2.0", new DateTime(2018, 04, 11), "增加ResolveAsSingleton的支持;增加GuidHelper"));
     registry.AddWithAutoKey(VersionHistory.Create(VersionCategory, "0.3.0", new DateTime(2018, 04, 12), "增加模块化的支持;"));
     registry.AddWithAutoKey(VersionHistory.Create(VersionCategory, "0.4.0", new DateTime(2018, 04, 19), "增加产品、特性支持;"));
 }
Пример #4
0
        public override void Load()
        {
            base.Load();

            this.History = VersionHistory.GetHistory();
            this.Version = string.Format(Strings.Update_Label_Version, VersionHistory.GetVersion().ToString(3));
        }
Пример #5
0
 public void SaveExplicitVersion()
 {
     ExpectedVersion = this.Node.Version;
     if (this.Node.Id != 0 && this.LatestVersion == (VersionNumber)this.Node.GetStoredValue("Version"))
     {
         ExpectedVersionId = VersionHistory.Last().VersionId;
     }
 }
Пример #6
0
        public TestStateManager(ITestConverter converter, Test test)
        {
            _converter = converter;
            _test      = test;
            _history   = new VersionHistory();

            _undoCommand = new ActionCommand(undo);
            _redoCommand = new ActionCommand(redo);

            Version(null);
            RecordSnapshot();
        }
Пример #7
0
        private void InsertInitialRecord(OpsisContext db)
        {
            var init = new VersionHistory
            {
                Id            = 1,
                InitDate      = DateTime.Now,
                VersionNumber = "1.0"
            };

            db.VersionHistories.Add(init);
            db.SaveChanges();
        }
Пример #8
0
        public void Constructor_GivenValues_ThenPopulatesProperties()
        {
            var versionHistory = new VersionHistory(new Version(1, 2), new Version(3, 4));

            Assert.NotNull(versionHistory?.Introduced);
            Assert.Equal(1, versionHistory.Introduced.Major);
            Assert.Equal(2, versionHistory.Introduced.Minor);

            Assert.NotNull(versionHistory?.Deprecated);
            Assert.Equal(3, versionHistory.Deprecated.Major);
            Assert.Equal(4, versionHistory.Deprecated.Minor);
        }
        public async Task <VersionedDocument <T> > InsertDocumentAsync(
            ObjectId objectId,
            T doc)
        {
            VersionedDocument <T> currentDocument = null;

            if (objectId != ObjectId.Empty)
            {
                currentDocument = await(await Collection.FindAsync(x => x.Id == objectId)).FirstOrDefaultAsync();
            }

            if (currentDocument == null)
            {
                var versionedDoc = new VersionedDocument <T>(doc);
                Collection.InsertOne(versionedDoc);
                return(versionedDoc);
            }

            var    previousVersionNumber = currentDocument.Version;
            JToken jtokenCurrentDoc      = currentDocument.Current == null
                ? JToken.Parse("{}")
                : JToken.FromObject(currentDocument.Current);

            JToken diff = _jdp.Diff(jtokenCurrentDoc, JToken.FromObject(doc));

            if (diff == null)
            {
                return(null);              // no change
            }
            currentDocument.Current = doc;
            VersionHistory versionHistory = new VersionHistory(diff.ToString(Formatting.None))
            {
                Version = previousVersionNumber,
                UtcDate = currentDocument.UtcDate,
                Type    = currentDocument.Type
            };

            currentDocument.UtcDate = DateTime.UtcNow;
            currentDocument.Prev.Add(versionHistory);
            currentDocument.Version   = previousVersionNumber + 1;
            currentDocument.IsDeleted = false;
            currentDocument.Type      = doc.GetType().ToString();
            var result = Collection.ReplaceOne(item => item.Id == objectId, currentDocument);

            if (result.ModifiedCount != 1) // the number of modified documents
            {
                // print("Someone must have gotten there first, re-fetch the new document, try again");
                // todo - är det här något som kan uppstå?
            }

            return(null);
        }
Пример #10
0
        public void LogUserProfileVersion(UserProfile up)
        {
            //UserProfile up = GetUserProfile(nurseId);
            XElement xml = GenerateUserProfileXml(up);

            VersionHistory vh = new VersionHistory();

            vh.nurseId          = up.id;
            vh.modificationDate = DateTime.Now;
            vh.modifiedBy       = up.Nurse.lastModifiedBy;

            vh.versionXml = xml.ToString();

            db.VersionHistories.InsertOnSubmit(vh);

            db.SubmitChanges();
        }
Пример #11
0
        public override TVersionable Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
        {
            if (reader.TokenType != JsonTokenType.StartObject)
            {
                throw new JsonException();
            }

            var output = Activator.CreateInstance <TVersionable>();

            var objectVersionHistory = typeof(TVersionable).GetVersionHistory();

            while (reader.Read())
            {
                if (reader.TokenType == JsonTokenType.EndObject)
                {
                    return(output);
                }

                if (reader.TokenType != JsonTokenType.PropertyName)
                {
                    throw new JsonException();
                }

                var propertyName = reader.GetString();
                var propertyInfo = typeof(TVersionable).GetPropertyBySerialisationName(propertyName);

                if (propertyInfo != null)
                {
                    var propertyVersionHistory   = propertyInfo.GetVersionHistory();
                    var applicableVersionHistory = VersionHistory.Merge(propertyVersionHistory, objectVersionHistory);

                    if (applicableVersionHistory.IsApplicableAtVersion(_version))
                    {
                        var value = JsonSerializer.Deserialize(ref reader, propertyInfo.PropertyType, options);
                        propertyInfo.SetValue(output, value);
                    }
                }
            }

            throw new JsonException();
        }
Пример #12
0
        public override void Write(Utf8JsonWriter writer, TVersionable value, JsonSerializerOptions options)
        {
            writer.WriteStartObject();

            var objectVersionHistory = typeof(TVersionable).GetVersionHistory();

            foreach (var propertyInfo in typeof(TVersionable).GetProperties())
            {
                var propertyVersionHistory   = propertyInfo.GetVersionHistory();
                var applicableVersionHistory = VersionHistory.Merge(propertyVersionHistory, objectVersionHistory);

                if (applicableVersionHistory.IsApplicableAtVersion(_version))
                {
                    writer.WritePropertyName(propertyInfo.GetSerialisationName());

                    JsonSerializer.Serialize(writer, propertyInfo.GetValue(value), options);
                }
            }

            writer.WriteEndObject();
        }
Пример #13
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["id"] != null)
            {
                var            versionid = int.Parse(Request.QueryString["id"]);
                VersionHistory version   = _mBs.GetVersion(versionid);

                if (version != null)
                {
                    string            s = version.versionXml;
                    XmlReader         reader;
                    XmlReaderSettings rs = new XmlReaderSettings();
                    StringBuilder     sb = new StringBuilder();
                    rs.CloseInput       = true;
                    rs.IgnoreComments   = true;
                    rs.ConformanceLevel = ConformanceLevel.Fragment;

                    reader = XmlReader.Create(new System.IO.StringReader(s), rs);

                    // Create the XslCompiledTransform and load the stylesheet.
                    System.Xml.Xsl.XslCompiledTransform xslt = new System.Xml.Xsl.XslCompiledTransform();
                    String path = Server.MapPath(ResolveUrl("Version.xslt"));
                    xslt.Load(path);

                    // Create the XsltArgumentList.
                    System.Xml.Xsl.XsltArgumentList xslArg = new System.Xml.Xsl.XsltArgumentList();

                    xslArg.AddParam("modificationdate", "", version.modificationDate.ToString());
                    xslArg.AddParam("versionid", "", version.id.ToString());
                    xslArg.AddParam("modifiedby", "", version.modifiedBy);

                    System.IO.TextWriter tw = new System.IO.StringWriter(sb);

                    //Transform the version xml.
                    xslt.Transform(reader, xslArg, tw);
                    litVersionData.Text = sb.ToString();
                }
            }
        }
        public async Task DeleteDocumentAsync(
            ObjectId objectId)
        {
            // todo - check if we delete an already deleted document, then return
            var    currentDocument       = (await Collection.FindAsync(x => x.Id == objectId)).First();
            var    previousVersionNumber = currentDocument.Version;
            JToken diff = _jdp.Diff(JToken.FromObject(currentDocument.Current), JToken.Parse("{}"));

            currentDocument.Current = null;
            VersionHistory versionHistory = new VersionHistory(diff.ToString(Formatting.None))
            {
                Version   = previousVersionNumber,
                UtcDate   = currentDocument.UtcDate,
                IsDeleted = true,
                Type      = currentDocument.Type
            };

            currentDocument.UtcDate = DateTime.UtcNow;
            currentDocument.Prev.Add(versionHistory);
            currentDocument.Version   = previousVersionNumber + 1;
            currentDocument.IsDeleted = true;
            Collection.ReplaceOne(item => item.Id == objectId, currentDocument);
        }
        private static IDictionary <string, OpenApiSchema> GetPrunedSchemas(IDictionary <string, OpenApiSchema> schemas, Version version)
        {
            var prunedSchemas = new Dictionary <string, OpenApiSchema>();

            foreach (var schema in schemas.Where(s => s.Value?.Description != null))
            {
                var objectData = schema.Value.Description;

                // VersionableSwaggerSchemaAttribute packs data as "@[ClassName]@Description
                var regEx   = new Regex(@"^@\[(?'className'[\s\S]+)\]@(?'description'[\s\S]*)$");
                var matches = regEx.Matches(objectData);

                if (matches.Count == 0)
                {
                    // Not decorated with VersionableSwaggerSchemaAttribute so pass through untouched
                    prunedSchemas.Add(schema.Key, schema.Value);
                    continue;
                }

                var objectName = matches[0].Groups["className"].Value;
                schema.Value.Description = matches[0].Groups["description"].Value;

                if (string.IsNullOrWhiteSpace(objectName))
                {
                    // Can't determine Versionable object so pass through untouched
                    prunedSchemas.Add(schema.Key, schema.Value);
                    continue;
                }

                var objectType = Type.GetType(objectName);

                if (objectType == null || !objectType.IsClass)
                {
                    // Not Versionable so pass through untouched
                    prunedSchemas.Add(schema.Key, schema.Value);
                    continue;
                }

                var objectVersionHistory = objectType.GetVersionHistory();

                if (!objectVersionHistory.IsApplicableAtVersion(version))
                {
                    // Entire object not applicable - discard
                    continue;
                }

                var excludedProperties = new List <string>();

                foreach (var property in schema.Value.Properties)
                {
                    var propertyInfo = objectType.GetPropertyBySerialisationName(property.Key);

                    if (propertyInfo == null)
                    {
                        continue;
                    }

                    var propertyVersionHistory   = propertyInfo.GetVersionHistory();
                    var applicableVersionHistory = VersionHistory.Merge(propertyVersionHistory, objectVersionHistory);

                    if (!applicableVersionHistory.IsApplicableAtVersion(version))
                    {
                        excludedProperties.Add(property.Key);
                    }
                }

                foreach (var excludedProperty in excludedProperties.Where(excludedProperty => schema.Value.Properties.ContainsKey(excludedProperty)))
                {
                    schema.Value.Properties.Remove(excludedProperty);
                }

                prunedSchemas.Add(schema.Key, schema.Value);
            }

            return(prunedSchemas);
        }
Пример #16
0
        public void IsApplicableAtVersion_GivenIntroducedAfter_AndDeprecatedAfter_ThenReturnsFalse()
        {
            var versionHistory = new VersionHistory(new Version(2, 2), new Version(2, 6));

            Assert.False(versionHistory.IsApplicableAtVersion(new Version(2, 0)));
        }
Пример #17
0
        public void IsApplicableAtVersion_GivenIntroducedBefore_AndDeprecatedAfter_ThenReturnsTrue()
        {
            var versionHistory = new VersionHistory(new Version(1, 0), new Version(2, 3));

            Assert.True(versionHistory.IsApplicableAtVersion(new Version(2, 0)));
        }
Пример #18
0
        public void IsApplicableAtVersion_GivenDefault_ThenReturnsTrue()
        {
            var versionHistory = new VersionHistory(new Version());

            Assert.True(versionHistory.IsApplicableAtVersion(new Version(2, 0)));
        }
Пример #19
0
        private void button2_Click(object sender, EventArgs e)
        {
            Alfresco.RepositoryWebService.Store[] stores = this.repoService.getStores();

            Alfresco.RepositoryWebService.Store vStore = stores[3];

            ListViewItem item = listViewBrowse.SelectedItems[0];

            if (item != null)
            {
                ResultSetRowNode node = item.Tag as ResultSetRowNode;
                if (node != null)
                {
                    if (node.type.Contains("folder") == false)
                    {
                        // Create the reference for the node selected
                        Alfresco.AuthoringWebService.Store spacesStore2 = new Alfresco.AuthoringWebService.Store();
                        spacesStore2.scheme  = Alfresco.AuthoringWebService.StoreEnum.workspace;
                        spacesStore2.address = "SpacesStore";

                        Alfresco.AuthoringWebService.Reference reference = new Alfresco.AuthoringWebService.Reference();
                        reference.store = spacesStore2;
                        reference.uuid  = node.id;

                        VersionHistory VH = this.authoringService.getVersionHistory(reference);

                        int    i    = 0;
                        char[] temp = new char[1];
                        temp[0] = '0';
                        string versions = new string(temp);
                        Alfresco.AuthoringWebService.Version first;
                        foreach (Alfresco.AuthoringWebService.Version version in VH.versions)
                        {
                            if (i == 0)
                            {
                                first = version;
                            }
                            versions += version.label + (";") + version.id.uuid + (";");
                        }

                        {
                            // Create the reference for the node selected
                            Alfresco.ContentWebService.Store spacesStore3 = new Alfresco.ContentWebService.Store();
                            spacesStore3.scheme  = Alfresco.ContentWebService.StoreEnum.versionStore;
                            spacesStore3.address = vStore.address;

                            Alfresco.ContentWebService.Reference reference1 = new Alfresco.ContentWebService.Reference();
                            reference1.store = spacesStore3;
                            reference1.uuid  = VH.versions[VH.versions.GetUpperBound(0)].id.uuid;

                            // Lets try and get the content
                            Alfresco.ContentWebService.Predicate predicate = new Alfresco.ContentWebService.Predicate();
                            predicate.Items = new Object[] { reference1 };
                            Content[] contents = this.contentService.read(predicate, "{http://www.alfresco.org/model/content/1.0}content");
                            Content   content  = contents[0];
                            if (content.url != null && content.url.Length != 0)
                            {
                                string url = content.url + "?ticket=" + AuthenticationUtils.Ticket;
                                webBrowser.Url = new Uri(url);
                            }
                        }
                    }
                    else
                    {
                    }
                }
            }
        }
Пример #20
0
 public void SetUp()
 {
     history = new VersionHistory();
 }