示例#1
0
 public int Create(Models.Format format)
 {
     Data.Format newFormat = new Data.Format {
         Description = format.Description
     };
     db.Formats.Add(newFormat);
     db.SaveChanges();
     return(newFormat.Id);
 }
        private void ParseOutputRectangles(string[] output_lines)
        {
            GameObject board = null;

            totalBoardsTxt.text = output_lines[0];
            areaWasteTxt.text   = output_lines[1];
            for (int i = 3; i < output_lines.Length; ++i)
            {
                string[] words = output_lines[i].Split(' ');
                if (words.Length == 2)
                {
                    // Format: Plancha 1
                    board = Instantiate(boardPrefab, transform);
                    var boardGrid = board.transform.GetChild(0);
                    boardGrid.localScale = gridScale;
                    board.SetActive(false);
                    storeBoardsComponent.Boards.Add(board);
                }
                else
                {
                    // Format: A1 150 154 G
                    var           id       = words[0];
                    var           formatId = Regex.Replace(id, @"[\d]", string.Empty);
                    Models.Format format   = formats[formatId];
                    float         width    = formats[formatId].Width;
                    float         height   = formats[formatId].Height;
                    var           x        = float.Parse(words[1]);
                    var           y        = float.Parse(words[2]);
                    var           rotated  = words[3] == "N" ? false : true;
                    if (rotated)
                    {
                        (width, height) = (height, width);
                    }
                    var area = new Rect
                    {
                        x      = x,
                        y      = y,
                        width  = width,
                        height = height
                    };
                    // Rectangles Transform GameObject
                    var rectanglesTransform      = board.transform.GetChild(1);
                    var storeRectanglesComponent = rectanglesTransform.GetComponent <StoreRectanglesComponent>();
                    var rectangle = new Models.Rectangle()
                    {
                        id   = id,
                        area = area
                    };
                    storeRectanglesComponent.CreateRectangle(rectangle);
                }
            }
            if (storeBoardsComponent.Boards.Count > 0)
            {
                storeBoardsComponent.Boards[0].SetActive(true);
            }
        }
示例#3
0
        public Models.Format Update(Models.Format format)
        {
            var existing = db.Formats.SingleOrDefault(x => x.Id == format.Id);

            if (existing != null)
            {
                existing.Description = format.Description;
                db.SaveChanges();
            }
            return(null);
        }
 private bool IsFormatUsed(Models.Format format)
 {
     for (int i = 0; i < formats.Count; i++)
     {
         if (formats[i] == format)
         {
             return(true);
         }
     }
     return(false);
 }
        /// <summary>
        /// The code generation endpoint. The response is a path to the generated zip file relative to https://apimatic.io/
        /// </summary>
        /// <param name="name">Required parameter: The name of the API being used for code generation</param>
        /// <param name="format">Required parameter: The format of the API description to use for code generation</param>
        /// <param name="template">Required parameter: The template to use for code generation</param>
        /// <param name="body">Required parameter: The input file to use for code generation</param>
        /// <param name="dl">Optional parameter: Optional</param>
        /// <return>Returns the string response from the API call</return>
        public string UsingFileAsString(
            string name,
            Models.Format format,
            Models.Template template,
            FileStreamInfo body,
            int?dl = 0)
        {
            Task <string> t = UsingFileAsStringAsync(name, format, template, body, dl);

            APIHelper.RunTaskSynchronously(t);
            return(t.Result);
        }
        /// <summary>
        /// Download API description from the given URL and convert it to the given format. The API description format of the provided file will be detected automatically. The response is generated zip file as per selected template.
        /// </summary>
        /// <param name="template">Required parameter: The template to use for code generation</param>
        /// <param name="format">Required parameter: The format of the API description to use for code generation</param>
        /// <param name="name">Required parameter: The name of the API being used for code generation</param>
        /// <param name="descriptionUrl">Required parameter: The absolute public Uri for an API description doucment</param>
        /// <param name="dl">Optional parameter: Optional</param>
        /// <return>Returns the Stream response from the API call</return>
        public Stream UsingUrlAsBinary(
            Models.Template template,
            Models.Format format,
            string name,
            string descriptionUrl,
            int?dl = 1)
        {
            Task <Stream> t = UsingUrlAsBinaryAsync(template, format, name, descriptionUrl, dl);

            APIHelper.RunTaskSynchronously(t);
            return(t.Result);
        }
        /// <summary>
        /// The code generation endpoint! Upload a file and convert it to the given format. The API description format of uploaded file will be detected automatically. The response is generated zip file as per selected template.
        /// </summary>
        /// <param name="name">Required parameter: The name of the API being used for code generation</param>
        /// <param name="format">Required parameter: The format of the API description to use for code generation</param>
        /// <param name="template">Required parameter: The template to use for code generation</param>
        /// <param name="body">Required parameter: The input file to use for code generation</param>
        /// <param name="dl">Optional parameter: Optional</param>
        /// <return>Returns the Stream response from the API call</return>
        public Stream UsingFileAsBinary(
            string name,
            Models.Format format,
            Models.Template template,
            FileStreamInfo body,
            int?dl = 1)
        {
            Task <Stream> t = UsingFileAsBinaryAsync(name, format, template, body, dl);

            APIHelper.RunTaskSynchronously(t);
            return(t.Result);
        }
        /// <summary>
        /// The code generation endpoint. The response is a path to the generated zip file relative to https://apimatic.io/
        /// </summary>
        /// <param name="template">Required parameter: The template to use for code generation</param>
        /// <param name="format">Required parameter: The format of the API description to use for code generation</param>
        /// <param name="name">Required parameter: The name of the API being used for code generation</param>
        /// <param name="descriptionUrl">Required parameter: The absolute public Uri for an API description doucment</param>
        /// <param name="dl">Optional parameter: Optional</param>
        /// <return>Returns the string response from the API call</return>
        public string UsingUrlAsString(
            Models.Template template,
            Models.Format format,
            string name,
            string descriptionUrl,
            int?dl = 0)
        {
            Task <string> t = UsingUrlAsStringAsync(template, format, name, descriptionUrl, dl);

            APIHelper.RunTaskSynchronously(t);
            return(t.Result);
        }
示例#9
0
        public Models.Format GetById(int id)
        {
            var existing = db.Formats.SingleOrDefault(x => x.Id == id);

            if (existing == null)
            {
                return(null);
            }
            Models.Format f = new Models.Format {
                Id = existing.Id, Description = existing.Description
            };

            return(f);
        }
示例#10
0
        public ActionResult Save(AppNewDocumentViewModel model, string templateName, int selected)
        {
            model.AllControls.RemoveAll(r => r.Tag.Contains("//comment")); // delete labels from list
            Models.Format format   = _formatsRepository.GetFormat(selected);
            Models.File   template = _filesReopository.GetFiles(Request.MapPath("~/TemplateFiles/")).Find(x => x.FileName == templateName);

            _controlsRepository.SaveContols(model.AllControls);
            Word   word         = new Word();
            string fileInfoHash = word.SaveDocument(model.AllControls, template, format);

            ViewBag.InfoHash = fileInfoHash;
            ViewBag.Type     = 2;
            ViewBag.Message  = "Zapisano plik ";
            return(View());
        }
        public void GenerateFile()
        {
            formats = new List <Models.Format>();
            System.Random random = new System.Random();
            int           width = random.Next(1, 101);
            int           height = random.Next(1, 101);
            int           formatsNumber = random.Next(1, 101);
            int           unitsNumber = random.Next(1, 101);
            int           formatWidth, formatHeight, formatCount;
            string        format = "A";

            for (int i = 0; i < formatsNumber; i++)
            {
                formatWidth  = random.Next(1, width + 1);
                formatHeight = random.Next(1, height + 1);
                formatCount  = random.Next(1, unitsNumber);

                Models.Format newFormat = new Models.Format()
                {
                    Id = format, Width = formatWidth, Height = formatHeight, Quantity = formatCount
                };

                if (IsFormatUsed(newFormat))
                {
                    --i;
                    continue;
                }

                formats.Add(newFormat);
                format = GetNextString(format);
            }

            using (StreamWriter file = new StreamWriter(@"Assets\input.txt"))
            {
                file.WriteLine($"{width} {height}");
                file.WriteLine($"{formatsNumber}");

                foreach (var item in formats)
                {
                    file.WriteLine($"{item.Id} {item.Width} {item.Height} {item.Quantity}");
                }
            }
        }
        private void ParseInputFormats(string[] input_lines)
        {
            var total_formats = int.Parse(input_lines[1]);

            for (var i = 2; i < total_formats + 2; ++i)
            {
                var properties = input_lines[i].Split(' ');
                var id         = properties[0];
                var width      = int.Parse(properties[1]);
                var height     = int.Parse(properties[2]);
                var count      = int.Parse(properties[3]);
                formats[id] = new Models.Format
                {
                    Id       = id,
                    Width    = width,
                    Height   = height,
                    Quantity = count
                };
            }
        }
        protected override void Seed(LibraryEntities context)
        {
            Subject Antiquarian = new Subject()
            {
                Name = "Antiquarian, Rare & Collectable"
            };
            Subject Biography = new Subject()
            {
                Name = "Biography"
            };
            Subject Crime = new Subject()
            {
                Name = "Crime, Thrillers & Mystery"
            };
            Subject History = new Subject()
            {
                Name = "History"
            };
            Subject Horror = new Subject()
            {
                Name = "Horror"
            };
            Subject Romance = new Subject()
            {
                Name = "Romance"
            };
            Subject SciFiAndFantasy = new Subject()
            {
                Name = "Science Fiction & Fantasy"
            };
            Subject Travel = new Subject()
            {
                Name = "Travel & Holiday"
            };

            context.Subjects.Add(Antiquarian);
            context.Subjects.Add(Biography);
            context.Subjects.Add(Crime);
            context.Subjects.Add(History);
            context.Subjects.Add(Horror);
            context.Subjects.Add(Romance);
            context.Subjects.Add(SciFiAndFantasy);
            context.Subjects.Add(Travel);

            Format Hardcover = new Models.Format()
            {
                Name = "Hardcover"
            };
            Format Paperback = new Models.Format()
            {
                Name = "Paperback"
            };
            Format Kindle = new Models.Format()
            {
                Name = "Kindle Books"
            };

            context.Formats.Add(Hardcover);
            context.Formats.Add(Paperback);
            context.Formats.Add(Kindle);

            Author LKHamilton = new Author()
            {
                Name = "Laurell K. Hamilton"
            };
            Author KCast = new Author()
            {
                Name = "Kristin Cast"
            };
            Author PCCast = new Author()
            {
                Name = "P. C. Cast"
            };
            Author RPike = new Author()
            {
                Name = "Richard Pike"
            };
            Author CGibson = new Author()
            {
                Name = "Chris Gibson"
            };
            Author RVincent = new Author()
            {
                Name = "Rachel Vincent"
            };
            Author CHarris = new Author()
            {
                Name = "Charlaine Harris"
            };
            Author JLake = new Author()
            {
                Name = "John Lake"
            };
            Author MStyling = new Author()
            {
                Name = "Mark Styling"
            };
            Author CWSmith = new Author()
            {
                Name = "Charles William Smith"
            };
            Author CTomalin = new Author()
            {
                Name = "Claire Tomalin"
            };
            Author ASugar = new Author()
            {
                Name = "Alan Sugar"
            };
            Author TPratchett = new Author()
            {
                Name = "Sir Terry Pratchett"
            };
            Author REFeist = new Author()
            {
                Name = "Raymond E. Feist"
            };
            Author PIrvine = new Author()
            {
                Name = "Peter Irvine"
            };
            Author DFriebe = new Author()
            {
                Name = "Daniel Friebe"
            };
            Author KDoner = new Author()
            {
                Name = "Kim Doner"
            };

            context.Authors.Add(LKHamilton);
            context.Authors.Add(KCast);
            context.Authors.Add(PCCast);
            context.Authors.Add(RPike);
            context.Authors.Add(CGibson);
            context.Authors.Add(RVincent);
            context.Authors.Add(CHarris);
            context.Authors.Add(JLake);
            context.Authors.Add(MStyling);
            context.Authors.Add(CWSmith);
            context.Authors.Add(CTomalin);
            context.Authors.Add(ASugar);
            context.Authors.Add(TPratchett);
            context.Authors.Add(REFeist);
            context.Authors.Add(PIrvine);
            context.Authors.Add(DFriebe);
            context.Authors.Add(KDoner);

            context.Books.Add(new Book()
            {
                Title           = "The Lightning Boys: True Tales from Pilots of the English Electric Lightning",
                Price           = 12.25M,
                Isbn            = "190811715X",
                PublicationDate = new DateTime(2011, 7, 14),
                Format          = Hardcover,
                Subject         = History,
                Authors         = new List <Author>()
                {
                    RPike
                }
            });

            context.Books.Add(new Book()
            {
                Title           = "Awakened (House of Night)",
                Price           = 4.12M,
                Isbn            = "1905654855",
                PublicationDate = new DateTime(2011, 10, 25),
                Format          = Paperback,
                Subject         = Horror,
                Authors         = new List <Author>()
                {
                    KCast, PCCast
                }
            });

            context.Books.Add(new Book()
            {
                Title           = "Destined: A House of Night Novel",
                Price           = 6.49M,
                Isbn            = "1905654871",
                PublicationDate = new DateTime(2011, 10, 25),
                Format          = Hardcover,
                Subject         = Horror,
                Authors         = new List <Author>()
                {
                    KCast, PCCast
                }
            });

            context.Books.Add(new Book()
            {
                Title           = "Dragon's Oath: A House of Night Novella",
                Price           = 3.82M,
                Isbn            = "1907411186",
                PublicationDate = new DateTime(2011, 7, 12),
                Format          = Paperback,
                Subject         = Horror,
                Authors         = new List <Author>()
                {
                    KCast, PCCast
                }
            });

            context.Books.Add(new Book()
            {
                Title           = "Dragon's Oath: A House of Night Novella",
                Price           = 3.56M,
                Isbn            = "1907410708",
                PublicationDate = new DateTime(2010, 10, 26),
                Format          = Hardcover,
                Subject         = Horror,
                Authors         = new List <Author>()
                {
                    PCCast, KDoner
                }
            });

            context.Books.Add(new Book()
            {
                Title           = "Bullet (Anita Blake, Vampire Hunter)",
                Price           = 4.55M,
                Isbn            = "0755352580",
                PublicationDate = new DateTime(2010, 11, 11),
                Format          = Paperback,
                Subject         = Horror,
                Authors         = new List <Author>()
                {
                    LKHamilton
                }
            });

            context.Books.Add(new Book()
            {
                Title           = "Incubus Dreams (Anita Blake Vampire Hunter 12)",
                Price           = 4.87M,
                Isbn            = "0755355407",
                PublicationDate = new DateTime(2010, 3, 4),
                Format          = Paperback,
                Subject         = Horror,
                Authors         = new List <Author>()
                {
                    LKHamilton
                }
            });

            context.Books.Add(new Book()
            {
                Title           = "Vulcan's Hammer: V-Force Aircraft and Weapons Projects Since 1945",
                Price           = 20.80M,
                Isbn            = "1902109171",
                PublicationDate = new DateTime(2011, 4, 30),
                Format          = Hardcover,
                Subject         = History,
                Authors         = new List <Author>()
                {
                    CGibson
                }
            });

            context.Books.Add(new Book()
            {
                Title           = "Deadlocked: A True Blood Novel",
                Price           = 14.24M,
                Isbn            = "0575096578",
                PublicationDate = new DateTime(2012, 5, 17),
                Format          = Hardcover,
                Subject         = Horror,
                Authors         = new List <Author>()
                {
                    CHarris
                }
            });

            context.Books.Add(new Book()
            {
                Title           = "B-52 Stratofortress Units 1955-73",
                Price           = 12.99M,
                Isbn            = "1841766070",
                PublicationDate = new DateTime(2004, 1, 16),
                Format          = Paperback,
                Subject         = History,
                Authors         = new List <Author>()
                {
                    JLake, MStyling
                }
            });

            context.Books.Add(new Book()
            {
                Title           = "Abstractions",
                Price           = 14517.21M,
                Isbn            = "B00085JQEI",
                PublicationDate = new DateTime(1939, 1, 1),
                Format          = Hardcover,
                Subject         = Antiquarian,
                Authors         = new List <Author>()
                {
                    CWSmith
                }
            });

            context.Books.Add(new Book()
            {
                Title           = "The Way I See It: Rants, Revelations And Rules For Life",
                Price           = 8.00M,
                Isbn            = "0230760899",
                PublicationDate = new DateTime(2011, 9, 29),
                Format          = Hardcover,
                Subject         = Biography,
                Authors         = new List <Author>()
                {
                    ASugar
                }
            });

            context.Books.Add(new Book()
            {
                Title           = "The Way I See It: Rants, Revelations And Rules For Life",
                Price           = 4.79M,
                Isbn            = "0230760899",
                PublicationDate = new DateTime(2011, 9, 29),
                Format          = Kindle,
                Subject         = Biography,
                Authors         = new List <Author>()
                {
                    ASugar
                }
            });

            context.Books.Add(new Book()
            {
                Title           = "Charles Dickens: A Life",
                Price           = 13.50M,
                Isbn            = "0670917672",
                PublicationDate = new DateTime(2011, 10, 6),
                Format          = Hardcover,
                Subject         = Biography,
                Authors         = new List <Author>()
                {
                    CTomalin
                }
            });

            context.Books.Add(new Book()
            {
                Title           = "What You See Is What You Get",
                Price           = 4.27M,
                Isbn            = "0330520474",
                PublicationDate = new DateTime(2010, 9, 30),
                Format          = Kindle,
                Subject         = Biography,
                Authors         = new List <Author>()
                {
                    ASugar
                }
            });

            context.Books.Add(new Book()
            {
                Title           = "Snuff: Discworld Novel 39",
                Price           = 8.99M,
                Isbn            = "038561926X",
                PublicationDate = new DateTime(2011, 10, 13),
                Format          = Hardcover,
                Subject         = SciFiAndFantasy,
                Authors         = new List <Author>()
                {
                    TPratchett
                }
            });

            context.Books.Add(new Book()
            {
                Title           = "I Shall Wear Midnight: Discworld Novel 38",
                Price           = 4.59M,
                Isbn            = "0552555592",
                PublicationDate = new DateTime(2011, 6, 9),
                Format          = Paperback,
                Subject         = SciFiAndFantasy,
                Authors         = new List <Author>()
                {
                    TPratchett
                }
            });

            context.Books.Add(new Book()
            {
                Title           = "I Shall Wear Midnight: Discworld Novel 38",
                Price           = 3.99M,
                Isbn            = "0552555592",
                PublicationDate = new DateTime(2011, 6, 9),
                Format          = Kindle,
                Subject         = SciFiAndFantasy,
                Authors         = new List <Author>()
                {
                    TPratchett
                }
            });

            context.Books.Add(new Book()
            {
                Title           = "Magician",
                Price           = 5.29M,
                Isbn            = "0586217835",
                PublicationDate = new DateTime(2008, 9, 1),
                Format          = Paperback,
                Subject         = SciFiAndFantasy,
                Authors         = new List <Author>()
                {
                    REFeist
                }
            });

            context.Books.Add(new Book()
            {
                Title           = "Silverthorn",
                Price           = 6.74M,
                Isbn            = "0007229429",
                PublicationDate = new DateTime(2008, 9, 1),
                Format          = Paperback,
                Subject         = SciFiAndFantasy,
                Authors         = new List <Author>()
                {
                    REFeist
                }
            });

            context.Books.Add(new Book()
            {
                Title           = "A Darkness at Sethanon",
                Price           = 5.29M,
                Isbn            = "0007229437",
                PublicationDate = new DateTime(2008, 9, 1),
                Format          = Paperback,
                Subject         = SciFiAndFantasy,
                Authors         = new List <Author>()
                {
                    REFeist
                }
            });

            context.Books.Add(new Book()
            {
                Title           = "Scotland The Best",
                Price           = 9.49M,
                Isbn            = "0007442440",
                PublicationDate = new DateTime(2011, 12, 8),
                Format          = Paperback,
                Subject         = Travel,
                Authors         = new List <Author>()
                {
                    PIrvine
                }
            });

            context.Books.Add(new Book()
            {
                Title           = "Mountain High: Europe's 50 Greatest Cycle Climbs",
                Price           = 10.00M,
                Isbn            = "0857386247",
                PublicationDate = new DateTime(2011, 10, 27),
                Format          = Hardcover,
                Subject         = Travel,
                Authors         = new List <Author>()
                {
                    DFriebe
                }
            });

            context.SaveChanges();
        }
        /// <summary>
        /// The code generation endpoint. The response is a path to the generated zip file relative to https://apimatic.io/
        /// </summary>
        /// <param name="name">Required parameter: The name of the API being used for code generation</param>
        /// <param name="format">Required parameter: The format of the API description to use for code generation</param>
        /// <param name="template">Required parameter: The template to use for code generation</param>
        /// <param name="body">Required parameter: The input file to use for code generation</param>
        /// <param name="dl">Optional parameter: Optional</param>
        /// <return>Returns the string response from the API call</return>
        public async Task <string> UsingFileAsStringAsync(
            string name,
            Models.Format format,
            Models.Template template,
            FileStreamInfo body,
            int?dl = 0)
        {
            //the base uri for api requests
            string _baseUri = Configuration.BaseUri;

            //prepare query string for API call
            StringBuilder _queryBuilder = new StringBuilder(_baseUri);

            _queryBuilder.Append("/codegen");

            //process optional query parameters
            APIHelper.AppendUrlWithQueryParameters(_queryBuilder, new Dictionary <string, object>()
            {
                { "name", name },
                { "format", Models.FormatHelper.ToValue(format) },
                { "template", Models.TemplateHelper.ToValue(template) },
                { "dl", (null != dl) ? dl : 0 }
            }, ArrayDeserializationFormat, ParameterSeparator);


            //validate and preprocess url
            string _queryUrl = APIHelper.CleanUrl(_queryBuilder);

            //append request with appropriate headers and parameters
            var _headers = new Dictionary <string, string>()
            {
                { "user-agent", "APIMATIC 2.0" }
            };

            //append form/field parameters
            var _fields = new List <KeyValuePair <string, Object> >()
            {
                new KeyValuePair <string, object>("body", body)
            };

            //remove null parameters
            _fields = _fields.Where(kvp => kvp.Value != null).ToList();

            //prepare the API call request to fetch the response
            HttpRequest _request = ClientInstance.Post(_queryUrl, _headers, _fields, Configuration.BasicAuthUserName, Configuration.BasicAuthPassword);

            //invoke request and get response
            HttpStringResponse _response = (HttpStringResponse)await ClientInstance.ExecuteAsStringAsync(_request).ConfigureAwait(false);

            HttpContext _context = new HttpContext(_request, _response);

            //Error handling using HTTP status codes
            if (_response.StatusCode == 401)
            {
                throw new APIException(@"Unauthorized: Access is denied due to invalid credentials.", _context);
            }

            if (_response.StatusCode == 412)
            {
                throw new APIException(@"Precondition Failed", _context);
            }

            //handle errors defined at the API level
            base.ValidateResponse(_response, _context);

            try
            {
                return(_response.Body);
            }
            catch (Exception _ex)
            {
                throw new APIException("Failed to parse the response: " + _ex.Message, _context);
            }
        }