Esempio n. 1
0
        private static TModel Create <TModel>() where TModel : UploadModelBase, new()
        {
            SelectListItem CreateItem(TimeSpan timespan) => new SelectListItem
            {
                Value = (DateTime.UtcNow + timespan).ToString("O"),
                Text  = timespan.Humanize()
            };

            SelectListItem CreateMonthItem(int month) => new SelectListItem
            {
                Value = CultureInfo.CurrentCulture.Calendar.AddMonths(DateTime.UtcNow, month).ToString("O"),
                Text  = $"{month} months"
            };

            TModel uploadModel = new TModel {
                FileIdentifier      = FileIdentifier.CreateNew(),
                Expiration          = DateTime.UtcNow.AddDays(7),
                AvailableExpiration = new[] {
                    CreateItem(TimeSpan.FromHours(1)),
                    CreateItem(TimeSpan.FromHours(4)),
                    CreateItem(TimeSpan.FromHours(8)),
                    CreateItem(TimeSpan.FromDays(1)),
                    CreateItem(TimeSpan.FromDays(2)),
                    CreateItem(TimeSpan.FromDays(7)),
                    CreateMonthItem(1),
                    CreateMonthItem(2),
                    CreateMonthItem(3),
                    CreateMonthItem(6),
                    CreateItem(TimeSpan.FromDays(CultureInfo.CurrentCulture.Calendar.GetDaysInYear(DateTime.UtcNow.Year))),
                }
            };

            return(uploadModel);
        }
Esempio n. 2
0
        private string GetModelDir <TModel>() where TModel : new()
        {
            var    model    = new TModel();
            string filename = SaveDir + @"\" + model.GetType().Name + @"\";

            return(filename);
        }
Esempio n. 3
0
        public TModel Resolve <TModel>() where TModel : IModel
        {
            IModel model      = GetModelByType <TModel>();
            TModel typedModel = (TModel)model;

            return(typedModel);
        }
Esempio n. 4
0
        public async Task <DeviceInfoModel> GetDeviceInfo(AccessPolicyModel accessPolicyModel, string deviceId, string access_token)
        {
            RequestDeviceModel requestDeviceModel = new RequestDeviceModel
            {
                apiVersion              = "2018-08-30-preview",
                authorizationPolicyKey  = accessPolicyModel.SharedAccessKey,
                authorizationPolicyName = accessPolicyModel.SharedAccessKeyName,
                hostName    = accessPolicyModel.HostName,
                requestPath = string.Format("/devices/{0}", deviceId)
            };
            string url     = "https://main.iothub.ext.azure.cn/api/dataPlane/get";
            var    request = new HttpRequestMessage(HttpMethod.Post, url);
            var    client  = this._clientFactory.CreateClient();

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", access_token);
            string requestbody = JsonConvert.SerializeObject(requestDeviceModel);

            request.Content = new StringContent(requestbody, UnicodeEncoding.UTF8, "application/json");
            var response = await client.SendAsync(request);

            string result = await response.Content.ReadAsStringAsync();

            if (response.IsSuccessStatusCode)
            {
                TModel <DeviceInfoModel> job = JsonConvert.DeserializeObject <TModel <DeviceInfoModel> >(result);
                return(job.body);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Creates the T model.
        /// </summary>
        /// <param name="tMName">Name of the t Model.</param>
        /// <param name="tMDescription">The t Model description.</param>
        /// <returns></returns>
        public static TModel CreateTModel(string tMName, string tMDescription)
        {
            TModel tModel = new TModel(tMName);

            tModel.Descriptions.Add(tMDescription);
            return(tModel);
        }
Esempio n. 6
0
 internal void RemoveInstance(TModel instance)
 {
     foreach (var index in base.Values)
     {
         index.RemoveInstance(instance);
     }
 }
Esempio n. 7
0
 protected ChangeResult(TModel model, TPropertiesEnum properties, bool success, string errorMessage)
 {
     Model        = model;
     Property     = properties;
     Success      = success;
     ErrorMessage = errorMessage;
 }
Esempio n. 8
0
 private IQueryable <ArtistVM> FetchAndPopulateAll()
 {
     return(TModel
            .Include(artist => artist.AlbumArtist)
            .ThenInclude(aa => aa.Album)
            .Select(artist => populateArtist(artist)));
 }
Esempio n. 9
0
        /// <summary>
        /// Gets the base model.
        /// </summary>
        /// <typeparam name="TModel">The type of the model.</typeparam>
        /// <returns>base model</returns>
        protected virtual TModel GetBaseModel <TModel>() where TModel : IVmOpenApiServiceBase, new()
        {
            var model = new TModel
            {
                Id                   = this.Id,
                SourceId             = this.SourceId,
                Type                 = this.Type,
                FundingType          = this.FundingType,
                ServiceChargeType    = this.ServiceChargeType,
                ServiceNames         = this.ServiceNames,
                AreaType             = this.AreaType,
                ServiceDescriptions  = this.ServiceDescriptions,
                Legislation          = this.Legislation,
                Languages            = this.Languages,
                Keywords             = this.Keywords,
                ServiceCoverageType  = this.ServiceCoverageType,
                Requirements         = this.Requirements,
                ServiceVouchersInUse = this.ServiceVouchersInUse,
                ServiceVouchers      = this.ServiceVouchers,
                PublishingStatus     = this.PublishingStatus,
                AvailableLanguages   = this.AvailableLanguages,
            };

            return(model);
        }
Esempio n. 10
0
    public static void WriteDataToText()
    {
        using (StreamWriter writer = new StreamWriter(filePath))
        {
            //header
            writer.Write("PartitionKey|RowKey|Timestamp|Id|");
            writer.WriteLine();

            do
            {
                TModel entity = null;
                //Read and remove entity from queue
                entitiesQueue.TryDequeue(out entity);

                if (entity != null)
                {
                    //Write data to text file
                    writer.Write("\"" + entity.PartitionKey + "\"|\"" + entity.RowKey + "\"|" + entity.Timestamp + "|" + entity.Id);
                    writer.WriteLine();
                }
                else
                {
                    //If all the entities are read out from the table and now there is no entities in the queue, we will break this loop and exit current thread.
                    if (ReadTableFinished)
                    {
                        break;
                    }
                }
            }while (true);
            writer.Dispose();
        }
    }
Esempio n. 11
0
        public TBetterCubeTraverse(TModel model)
        {
            R = model.R;

            LevelBorders = new List <TBorders>();

            for (int y = 0; y < R; ++y)
            {
                TBorders thisLevelBorders = new TBorders();
                for (int x = 0; x < R; ++x)
                {
                    for (int z = 0; z < R; ++z)
                    {
                        if (model[x, y, z] > 0)
                        {
                            MaxY = Math.Max(MaxY, y);

                            thisLevelBorders.MinX = Math.Min(thisLevelBorders.MinX, x);
                            thisLevelBorders.MaxX = Math.Max(thisLevelBorders.MaxX, x);

                            thisLevelBorders.MinZ = Math.Min(thisLevelBorders.MinZ, z);
                            thisLevelBorders.MaxZ = Math.Max(thisLevelBorders.MaxZ, z);
                        }
                    }
                }
                LevelBorders.Add(thisLevelBorders);
            }
        }
Esempio n. 12
0
            public void Finalize(TModel model, Range rangeZ)
            {
                if (model[Position.X + 1, Position.Y, Position.Z] > 0)
                {
                    var toFill = new Coord(Position.X + 1, Position.Y, Position.Z);
                    if (!FinalCoords.Contains(toFill))
                    {
                        CurrentCommand = new Fill(1, 0, 0);
                        FinalCoords.Add(toFill);
                        return;
                    }
                }

                var nextZ = Position.Z + FinalDirection;

                if (nextZ < 0 || nextZ > rangeZ.Max)
                {
                    if (Position.X == 0)
                    {
                        CurrentCommand = null;
                    }
                    else
                    {
                        Move(Position.X - 1, Position.Y, Position.Z);
                        FinalDirection = -FinalDirection;
                    }

                    return;
                }

                Move(Position.X, Position.Y, nextZ);
            }
Esempio n. 13
0
 public void Insert(TModel instance)
 {
     foreach (var index in base.Values)
     {
         index.Set(instance);
     }
 }
        /// <summary>
        /// Converts to version.
        /// </summary>
        /// <typeparam name="TModel">The type of the model.</typeparam>
        /// <returns>converted model</returns>
        protected TModel ConvertToDeliveryAddressVersionIn <TModel>() where TModel : IV7VmOpenApiAddressDeliveryIn, new()
        {
            var vm = new TModel()
            {
                Id = this.Id,
            };

            if (this.StreetAddress?.Count > 0)
            {
                vm.SubType       = AddressTypeEnum.Street.ToString();
                vm.StreetAddress = new VmOpenApiAddressStreetIn()
                {
                    Street                = this.StreetAddress,
                    StreetNumber          = this.StreetNumber,
                    PostalCode            = this.PostalCode,
                    Municipality          = this.Municipality,
                    AdditionalInformation = this.AdditionalInformations
                };
            }
            else
            {
                vm.SubType = AddressTypeEnum.PostOfficeBox.ToString();
                vm.PostOfficeBoxAddress = new VmOpenApiAddressPostOfficeBoxIn()
                {
                    PostOfficeBox         = PostOfficeBox,
                    PostalCode            = this.PostalCode,
                    Municipality          = this.Municipality,
                    AdditionalInformation = this.AdditionalInformations,
                };
            }

            return(vm);
        }
Esempio n. 15
0
        public Dictionary <string, string> GetModelList(Dictionary <string, List <Columns> > dict)
        {
            Dictionary <string, string> result = new Dictionary <string, string>();

            foreach (var tablename in dict.Keys)
            {
                List <Columns> columns = dict[tablename];
                TModel         model   = new TModel()
                {
                    ClassName      = GetCSharpNameFromSqlName(tablename),
                    Columns        = columns,
                    PkColumns      = columns.Where(p => p.PK).ToList(),
                    OtherColumns   = columns.Where(p => !p.PK).ToList(),
                    ModelSpaceName = "Mx",
                    Namespace      = baseClassNamespaces + ".Model",
                    TableName      = tablename,
                    ShareNamespace = "MXWater",
                    JsonName       = GetJsonNameFromSqlName(tablename),
                };

                string content = model.TransformText();

                result.Add(model.ClassName, content);
            }
            return(result);
        }
Esempio n. 16
0
        public TState(TModel model, bool enableValidation = false)
        {
            Model            = model;
            EnableValidation = enableValidation;
            Matrix           = new int[Model.R, Model.R, Model.R];

            var bot = new TBot
            {
                Bid   = 1,
                Coord =
                {
                    X = 0,
                    Y = 0,
                    Z = 0
                }
            };

            for (var i = 2; i <= 40; ++i)
            {
                bot.Seeds.Add(i);
            }

            Bots.Add(bot);

            Energy    = 0;
            Harmonics = EHarmonics.Low;
        }
Esempio n. 17
0
 private IQueryable <SeriesVM> FetchAndPopulateAll()
 {
     return(TModel
            .Include(series => series.Albums)
            .ThenInclude(album => album.AlbumArtist)
            .ThenInclude(aa => aa.Artist)
            .Select(series => populateSeries(series)));
 }
Esempio n. 18
0
        /// <summary>
        /// Creates the T model.
        /// </summary>
        /// <param name="tMName">Name of the t Model.</param>
        /// <param name="tMDescription">The t Model description.</param>
        /// <param name="tMKeyedRefence">The t Model keyed refence.</param>
        /// <returns></returns>
        public static TModel CreateTModel(string tMName, string tMDescription, KeyedReference tMKeyedRefence)
        {
            TModel tModel = new TModel(tMName);

            tModel.Descriptions.Add(tMDescription);
            tModel.CategoryBag.KeyedReferences.Add(tMKeyedRefence);
            return(tModel);
        }
Esempio n. 19
0
        public static TModel New <TModel>() where TModel : DbEntity, new()
        {
            var model = new TModel();

            model.ConfigureAsNew();

            return(model);
        }
Esempio n. 20
0
        List <ICommand> IStrategy.MakeTrace(TModel src, TModel dst)
        {
            var traceFile = $"{tracesDir}/{dst.Name}.nbt";

            return(File.Exists(traceFile)
                ? TraceReader.Read(traceFile)
                : new List <ICommand>());
        }
Esempio n. 21
0
        /// <summary>
        /// 把请求信息根据名称自动封装进TModel类型中,并返回该类型对象
        /// </summary>
        /// <typeparam name="TModel"></typeparam>
        /// <returns></returns>
        public TModel GetModel <TModel>()
        {
            TModel model = NFinal.Model.ModelHelper.GetModel <TModel>(this.parameters);

            System.Diagnostics.Debug.WriteLine(parameters.ToString());
            System.Diagnostics.Debug.WriteLine(model);
            return(model);
        }
 protected abstract IMachine GetMachineDesign(TModel mode, TContext context)
 {
     // Do some de-serialisation.
     return(new PrimaryAssemblyMachine(primarySysName,
                                       sysSerial,
                                       secondarySysName,
                                       primaryAssemblyLocation));
 }
Esempio n. 23
0
 public void Create(TModel model)
 {
     using (var context = new MyContext())
     {
         context.Set <TModel>().Attach(model);
         context.SaveChanges();
     }
 }
Esempio n. 24
0
        /// <summary>
        /// Выполняет привязку аргументов к свойствам модели.
        /// </summary>
        /// <typeparam name="TModel">Тип модели, содержащей привязываемые свойства.</typeparam>
        /// <returns>Возвращает объект с установленными значениями свойств.</returns>
        TModel Bind <TModel>() where TModel : new()
        {
            var model     = new TModel();
            var metadatas = MetadataProvider.ReadMetadata(typeof(TModel));

            BindUsingMetadata(model, metadatas);
            return(model);
        }
Esempio n. 25
0
 public FlatItemInfo(TModel item, Func <TModel, long> idProvider, Func <TModel, TModelWrapper> wrapper)
 {
     ViewType       = ItemViewType;
     Item           = item;
     Section        = null;
     Id             = idProvider(item);
     WrappedItem    = wrapper(item);
     WrappedSection = default(TModelCollectionWrapper);
 }
Esempio n. 26
0
        }//сделано

        public void LoadModelInfo(TModel CurrModel)
        {
            if (CurrModel == null)
            {
                return;
            }
            textBoxModelName.Text = CurrModel.ModelName;
            textBoxModelURL.Text  = CurrModel.ModelURL;
        }//сделано
        public TModel CreateModel <TModel, TPrimary>()
            where TModel : IVHModel <TModel, TPrimary>, new()
            where TPrimary : IVHEntity
        {
            // All TModel (e.g. CommonPersonModel) must have valid constructor (TPrimary primaryEntity) as Activator expectation
            TModel result = (TModel)Activator.CreateInstance(typeof(TModel), new object[] { this });

            return(result);
        }
Esempio n. 28
0
        public void BuildFromStat <TModel>()
            where TModel : NGramModelBase, new()
        {
            var stat  = new TextStatistician($"{PATH_BASE}stat.csv");
            var model = new TModel();

            model.FromStatistician(stat);
            model.Save();
        }
Esempio n. 29
0
            public void RemoveSeparatorIfLast(TModel model)
            {
                int count = modelAdapter.GetItemCount(model);

                if (count > 0 && modelAdapter.IsSeparatorAt(model, count - 1))
                {
                    modelAdapter.RemoveAt(model, count - 1);
                }
            }
Esempio n. 30
0
        public override void Process(long LSN)
        {
            //
            // Process change record hide by deleting the specified tModel.
            //
            TModel tModel = new TModel(TModelKey);

            tModel.Hide();
        }
Esempio n. 31
0
        /// <summary>
        ///   Publica ontologie cu numele si URL-ul specificat in campurile corespunzatoare (daca nu exista deja).
        /// </summary>
        private void performPublish()
        {
            String ontologyName = txbOntologyName.Text.Trim();
            String ontologyURL  = txbOntologyURL.Text.Trim();

            if (ontologyName == String.Empty || ontologyURL == String.Empty) {

                MessageBox.Show("All values must be set", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            try {

                FindTModel findTModel = new FindTModel(ontologyName);

                // uuid:a035a07c-f362-44dd-8f95-e2b134bf43b4  == uddi-org:general_keywords key
                KeyedReference categoryOntology = new KeyedReference("uuid:a035a07c-f362-44dd-8f95-e2b134bf43b4", "ontology", "QoS");

                findTModel.CategoryBag.Add(categoryOntology);

                findTModel.FindQualifiers.Add(FindQualifier.ExactNameMatch);

                TModelList tModelList = findTModel.Send(uddiConnection);

                if (0 == tModelList.TModelInfos.Count) {

                    TModel ontologyTModel = new TModel(ontologyName);

                    ontologyTModel.CategoryBag.Add(categoryOntology);

                    ontologyTModel.OverviewDoc.OverviewUrl = ontologyURL;

                    SaveTModel saveOntologyTModel = new SaveTModel(ontologyTModel);

                    saveOntologyTModel.Send(uddiConnection);

                    MessageBox.Show("Publish successful", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else {

                    MessageBox.Show("Ontology already exists");
                }
            }
            catch (UddiException e) {

                MessageBox.Show("Uddi error: "+ e.Message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception e){

                MessageBox.Show("General exception: " + e.Message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }