示例#1
0
        /// <summary>
        /// The read iteration model data from stream.
        /// </summary>
        /// <param name="stream">
        /// The stream.
        /// </param>
        /// <param name="password">
        /// The password.
        /// </param>
        /// <param name="iterationSetup">
        /// The iteration setup.
        /// </param>
        /// <returns>
        /// The model iteration contained <see cref="Thing"/> collection.
        /// </returns>
        /// <exception cref="FileLoadException">
        /// If file was not loaded properly
        /// </exception>
        private IEnumerable <Thing> ReadIterationModelDataFromStream(
            MemoryStream stream,
            string password,
            IterationSetup iterationSetup)
        {
            try
            {
                // read file, SiteDirectory first.
                using (var zip = ZipFile.Read(stream))
                {
                    // read iteration data
                    var iterationFilePath = string.Format(ExchangeFileNameFormat, iterationSetup.IterationIid);
                    var iterationZipEntry = zip.Entries.SingleOrDefault(x => x.FileName.EndsWith(iterationFilePath));
                    var iterationItems    = this.ReadInfoFromArchiveEntry(iterationZipEntry, password);

                    Logger.Info("{0} Iteration item(s) encountered", iterationItems.Count);
                    return(iterationItems);
                }
            }
            catch (Exception ex)
            {
                var msg = string.Format("{0}: {1}", "Failed to load file. Error", ex.Message);
                Logger.Error(msg);

                throw new FileLoadException(msg);
            }
        }
示例#2
0
        /// <summary>
        /// Get the model iteration from file.
        /// </summary>
        /// <param name="filePath">
        /// The file path.
        /// </param>
        /// <param name="password">
        /// The password.
        /// </param>
        /// <param name="iterationSetup">
        /// The iteration setup.
        /// </param>
        /// <returns>
        /// The deserialized iteration contained <see cref="Thing"/> collection.
        /// </returns>
        public IEnumerable <Thing> ReadModelIterationFromFile(
            string filePath,
            string password,
            IterationSetup iterationSetup)
        {
            var memoryStream = this.ReadFileToMemory(filePath);

            return(this.ReadIterationModelDataFromStream(memoryStream, password, iterationSetup));
        }
        /// <summary>
        /// Instantiate and deserialize the properties of a <paramref name="IterationSetup"/>
        /// </summary>
        /// <param name="jObject">The <see cref="JObject"/> containing the data</param>
        /// <returns>The <see cref="IterationSetup"/> to instantiate</returns>
        public static CDP4Common.DTO.IterationSetup FromJsonObject(JObject jObject)
        {
            var iid            = jObject["iid"].ToObject <Guid>();
            var revisionNumber = jObject["revisionNumber"].IsNullOrEmpty() ? 0 : jObject["revisionNumber"].ToObject <int>();
            var iterationSetup = new CDP4Common.DTO.IterationSetup(iid, revisionNumber);

            if (!jObject["createdOn"].IsNullOrEmpty())
            {
                iterationSetup.CreatedOn = jObject["createdOn"].ToObject <DateTime>();
            }

            if (!jObject["description"].IsNullOrEmpty())
            {
                iterationSetup.Description = jObject["description"].ToObject <string>();
            }

            if (!jObject["excludedDomain"].IsNullOrEmpty())
            {
                iterationSetup.ExcludedDomain.AddRange(jObject["excludedDomain"].ToObject <IEnumerable <Guid> >());
            }

            if (!jObject["excludedPerson"].IsNullOrEmpty())
            {
                iterationSetup.ExcludedPerson.AddRange(jObject["excludedPerson"].ToObject <IEnumerable <Guid> >());
            }

            if (!jObject["frozenOn"].IsNullOrEmpty())
            {
                iterationSetup.FrozenOn = jObject["frozenOn"].ToObject <DateTime?>();
            }

            if (!jObject["isDeleted"].IsNullOrEmpty())
            {
                iterationSetup.IsDeleted = jObject["isDeleted"].ToObject <bool>();
            }

            if (!jObject["iterationIid"].IsNullOrEmpty())
            {
                iterationSetup.IterationIid = jObject["iterationIid"].ToObject <Guid>();
            }

            if (!jObject["iterationNumber"].IsNullOrEmpty())
            {
                iterationSetup.IterationNumber = jObject["iterationNumber"].ToObject <int>();
            }

            if (!jObject["modifiedOn"].IsNullOrEmpty())
            {
                iterationSetup.ModifiedOn = jObject["modifiedOn"].ToObject <DateTime>();
            }

            if (!jObject["sourceIterationSetup"].IsNullOrEmpty())
            {
                iterationSetup.SourceIterationSetup = jObject["sourceIterationSetup"].ToObject <Guid?>();
            }

            if (!jObject["thingPreference"].IsNullOrEmpty())
            {
                iterationSetup.ThingPreference = jObject["thingPreference"].ToObject <string>();
            }

            return(iterationSetup);
        }