public static bool CanStoreItems(this IItemStorage itemStorage, IItemManager itemManager, ItemSlot itemSlot) { var slots = itemStorage.Slots.ToList(); // Test if we have enough inventory slots to store the items. if (!slots.Any(s => s.Empty)) { var item = itemManager.GetItem(itemSlot.ItemIndex); if (!item.Flags.HasFlag(ItemFlags.Stackable)) { return(false); } // If no slot is empty but the item is stackable we check // if there are slots with the same item and look if the // items would fit into these slots. int remainingCount = itemSlot.Amount; foreach (var slot in slots.Where(s => s.ItemIndex == itemSlot.ItemIndex)) { remainingCount -= (99 - slot.Amount); } // TODO: unlimited stack slots (merchants) if (remainingCount > 0) { return(false); } } return(true); }
void IAddItemScanTask.AssignScanWithRegistryItem(string fileName, int ownerID, int registryID, int itemNumber, string documentName, string documentDescription, string elementDescription, bool isMain, bool isRF) { IItemStorage storage = ItemStorageFactory.Create(); TypMime mimeType = MimeHelper.PobierzTypDlaRozszerzenia(Path.GetExtension(fileName)); Guid scanGuid = Guid.Empty; using (FileStream fs = File.OpenRead(fileName)) { scanGuid = storage.Save(fs); } XPathDocument xpd = new XPathDocument(File.OpenRead(Path.GetDirectoryName(fileName) + "\\" + Path.GetFileNameWithoutExtension(fileName) + ".xml")); XPathNavigator xpn = xpd.CreateNavigator(); Metadata md = new Metadata(); md.Add("dataPobrania", xpn.SelectSingleNode("/dokument/dataPobrania").Value); md.Add("nazwaPlikuSkanu", xpn.SelectSingleNode("/dokument/nazwaPlikuDokumentu").Value); md.Add("liczbaStron", xpn.SelectSingleNode("/dokument/liczbaStron").Value); md.Add("lokalizacjaSkanu", xpn.SelectSingleNode("/dokument/pochodzenie/lokalizacja").Value); md.Add("urzadzenie", xpn.SelectSingleNode("/dokument/pochodzenie/urzadzenie").Value); md.Add("rodzajSkanu", xpn.SelectSingleNode("/dokument/pochodzenie/rodzaj").Value); md.Add("zrodloSkanu", xpn.SelectSingleNode("/dokument/pochodzenie/zrodlo").Value); rdao.AddNewScan(ownerID, registryID, itemNumber, documentName, documentDescription, scanGuid, Path.GetFileName(fileName), elementDescription, mimeType.Nazwa, isMain, mimeType.Browsable, md.GetXml(), isRF); }
//Stream IDownloadFileTask.GetTempFileToPDF(string path, out string mimeType, out string fileName) //{ // if (!File.Exists(path)) // throw new ArgumentException("Nie ma takiego pliku"); // FileStream fs = File.OpenRead(path); // Image img = Image.FromStream(fs); // TiffImageSplitter tiff = new TiffImageSplitter(); // PdfDocument doc = new PdfDocument(); // int pageCount = tiff.getPageCount(img); // for (int i = 0; i < pageCount; i++) // { // PdfPage page = new PdfPage(); // Image tiffImg = tiff.getTiffImage(img, i); // XImage ximg = XImage.FromGdiPlusImage(tiffImg); // page.Width = ximg.PointWidth; // page.Height = ximg.PointHeight; // doc.Pages.Add(page); // XGraphics xgr = XGraphics.FromPdfPage(doc.Pages[i]); // xgr.DrawImage(ximg, 0, 0); // } // mimeType = "application/pdf"; // fileName = Path.ChangeExtension(Path.GetFileName(path), "pdf"); // MemoryStream ms = new MemoryStream(); // doc.Save(ms, false); // return ms; //} Stream IDownloadFileTask.GetFile(Guid imageID, out string mimeType, out string fileName, int pageNumber) { IItemStorage storage = ItemStorageFactory.Create(); DocumentDAO dao = new DocumentDAO(); DTO.DocumentItemDTO item = dao.GetItem(imageID); if (item == null) { throw new ArgumentException("Nie ma takiego pliku"); } mimeType = item.MimeType; fileName = item.OriginalName; if (pageNumber > 0 && mimeType.ToLower() == "image/tiff") { Image img = new Bitmap(storage.Load(imageID)); img.SelectActiveFrame(FrameDimension.Page, pageNumber - 1); MemoryStream ms = new MemoryStream(); img.Save(ms, System.Drawing.Imaging.ImageFormat.Tiff); return(ms); } else { return(storage.Load(imageID)); } }
public ProductDetailsWindow(Employee loggedInUser) { InitializeComponent(); allDepartments = GetAllDepartments(); this.loggedInUser = loggedInUser; LoadAllDepartments(); itemStorage = new ItemMySQL(); CheckPermisssions(); }
System.IO.Stream IGetImageTask.GetImage(Guid imageID) { IItemStorage storage = ItemStorageFactory.Create(); if (storage.Exists(imageID)) { return(storage.Load(imageID)); } return(null); }
public PurchaseViewModel(IPurchasePage view) { this.view = view; orderService = DependencyService.Get <IOrderService>(); cartService = DependencyService.Get <ICartService>(); userService = DependencyService.Get <IUserService>(); itemService = DependencyService.Get <IItemService>(); itemStorage = DependencyService.Get <IItemStorage>(); PurchaseCommand = new Command(() => OnPurchaseCommand()); }
/// <summary> /// Initializes a new instance of the <see cref="HttpService" /> class. /// </summary> public HttpService(IModuleManager moduleManager) { ApplicationInfo = new MemoryItemStorage(); BodyDecoder = new CompositeSerializer(); _service = this; _moduleManager = moduleManager; _encoder = new HttpMessageEncoder(); _decoder = new HttpMessageDecoder(BodyDecoder); _decoder.MessageReceived = OnMessageReceived; }
public static IEnumerable <string> GetImportantItemNames(this IItemStorage itemStorage, IItemManager itemManager) { foreach (var slot in itemStorage.Slots) { if (slot != null && slot.ItemIndex != 0) { var item = itemManager.GetItem(slot.ItemIndex); if (!item.Flags.HasFlag(ItemFlags.NotImportant)) { yield return(item.Name); } } } }
Stream IDownloadFileTask.GetTiffToPDF(Guid imageID, out string mimeType, out string fileName) { IItemStorage storage = ItemStorageFactory.Create(); DocumentDAO dao = new DocumentDAO(); DTO.DocumentItemDTO item = dao.GetItem(imageID); if (item == null) { throw new ArgumentException("Nie ma takiego pliku"); } if (item.MimeType.ToLower() == "image/tiff") { Image img = new Bitmap(storage.Load(imageID)); TiffImageSplitter tiff = new TiffImageSplitter(); PdfDocument doc = new PdfDocument(); int pageCount = tiff.getPageCount(img); for (int i = 0; i < pageCount; i++) { PdfPage page = new PdfPage(); Image tiffImg = tiff.getTiffImage(img, i); XImage ximg = XImage.FromGdiPlusImage(tiffImg); page.Width = ximg.PointWidth; page.Height = ximg.PointHeight; doc.Pages.Add(page); XGraphics xgr = XGraphics.FromPdfPage(doc.Pages[i]); xgr.DrawImage(ximg, 0, 0); } mimeType = "application/pdf"; fileName = Path.ChangeExtension(item.OriginalName, "pdf"); MemoryStream ms = new MemoryStream(); doc.Save(ms, false); return(ms); } else { throw new ArgumentException("Podany plik nie jest plikiem TIFF"); } }
/// <summary> /// Конструктор /// </summary> /// <param name="storage">Используемая реализация интерфейса</param> public InventoryController(IItemStorage storage) { _storage = storage; _bag = _storage.LoadInventory(); foreach (var item in _storage.LoadEquipment()) { _equipment[item.Key] = item.Value; } _mainHandSlot = _equipmentSlots.First(x => x.Value == InventorySlots.MainHand).Key; _offHandSlot = _equipmentSlots.First(x => x.Value == InventorySlots.OffHand).Key; _inputController = StartScript.GetStartScript.InputController; _inventoryView = GameObject.Find("InventoryMainView"); _inventoryView.SetActive(false); }
private void Awake() { GetStartScript = this; //Init non-unity systems QuestRepository.Init(); ItemTemplateRepository.Init(); _questStorage = new DbQuestStorage(); _itemStorage = new DbItemStorage(); //Get objects var Player = GameObject.FindGameObjectWithTag("Player"); var CameraCenter = GameObject.FindGameObjectWithTag("CameraCenter").transform; var PlayerAnimator = GameObject.FindGameObjectWithTag("PlayerAnimator"); //Создаем контроллеры AnimController = new AnimController(PlayerAnimator); InputController = new InputController(); CameraController = new CameraController(Camera.main.GetComponent <CameraModel>(), CameraCenter, Camera.main, InputController); MovementController = new MovementController(Player.transform, Player.GetComponent <CharController>()); StaminaController = new StaminaController(ref Player.GetComponent <StaminaModel>().Stamina, Player.GetComponent <StaminaModel>(), InputController, MovementController, AnimController); // enemyAttackController = new EnemyAttackController(targetDetector); HealthController = new HealthController(ref Player.GetComponent <HealthModel>().health, Player.GetComponent <HealthModel>()); QuestLogController = new QuestLogController(_questStorage); InventoryController = new InventoryController(_itemStorage); //Находим необходимые контроллеры которые висят на объектах SwordStartController = FindObjectOfType <SwordStartController>(); #region Добавляем контроллеры в коллекцию _allControllers.Add(InputController); _allControllers.Add(CameraController); _allControllers.Add(MovementController); _allControllers.Add(StaminaController); _allControllers.Add(AnimController); // AllControllers.Add(enemyAttackController); _allControllers.Add(HealthController); _allControllers.Add(QuestLogController); _allControllers.Add(InventoryController); #endregion }
public bool AddNewVersionOfDocumentItem(int documentId, Guid originalItemId, string description, Stream content, string mimeType, string name, DocumentItemCategory uploadMode) { IItemStorage storage = ItemStorageFactory.Create(); Guid itemId = storage.Save(content); Database db = DatabaseFactory.CreateDatabase(); try { db.ExecuteNonQuery("[Dokumenty].dodajNowaWersjeElementuDokumentu", documentId, itemId, originalItemId, description, mimeType, name, uploadMode); return(true); } catch { storage.Delete(itemId); return(false); } }
public ImageHelper(Guid id) { this._nazwaPlikuOryginalu = id.ToString() + "p"; IItemStorage storage = ItemStorageFactory.Create(); if (!storage.Exists(id)) { throw new ArgumentException("Nie ma takiego skanu"); } _obrazekRoboczy = System.Drawing.Image.FromStream(storage.Load(id), false, false); this._liczbaStron = _obrazekRoboczy.GetFrameCount(System.Drawing.Imaging.FrameDimension.Page); this._aktualnaStrona = 0; this._szerokosc = _obrazekRoboczy.Width; this._wysokosc = _obrazekRoboczy.Height; this._skala = poczatkowaSzerokosc * 100 / this._szerokosc; this.generujAktualnyObrazek(); }
public static bool HasAnyImportantItem(this IItemStorage itemStorage, IItemManager itemManager) { foreach (var slot in itemStorage.Slots) { if (slot != null && slot.ItemIndex != 0) { var item = itemManager.GetItem(slot.ItemIndex); if (item.IsImportant) { return(true); } } } return(false); }
public bool AddNewDocumentItem(int documentId, string originalName, string description, Stream content, string mimeType, ref Guid itemGuid, DocumentItemCategory uploadMode) { IItemStorage storage = ItemStorageFactory.Create(); Guid itemId = storage.Save(content); Database db = DatabaseFactory.CreateDatabase(); bool browsable = (mimeType == "image/tiff"); try { object res = db.ExecuteScalar("[Dokumenty].[dodajNowyElementDokumentu]", documentId, itemId, originalName, description, mimeType, false, browsable, uploadMode); itemGuid = res != null ? (Guid)res : Guid.Empty; return(true); } catch { storage.Delete(itemId); return(false); } }
void SaveESPDocumentAttachments(Guid docId, int newDocId) { IItemStorage storage = ItemStorageFactory.Create(); using (DbDataReader dr = (DbDataReader)(new DocumentDAO()).GetESPDocumentData(docId)) { if (dr.Read()) { string zalaczniki = dr["zalaczniki"].ToString(); XmlDocument attachments = new XmlDocument(); attachments.LoadXml(zalaczniki); foreach (XmlNode attachment in attachments.SelectNodes("//zalacznik")) { Guid attachId = new Guid(attachment.Attributes["id"].Value); Guid newItemId = new Guid(); Stream attachStream = storage.LoadGuid(attachId); attachStream.Seek(0, SeekOrigin.Begin); (new DocumentDAO()).AddNewDocumentItem(newDocId, attachment.Attributes["nazwa"].Value, "za³¹cznik", attachStream, attachment.Attributes["mime"].Value, ref newItemId, DocumentItemCategory.Uploaded); } } } }
public ItemService() { itemStorage = DependencyService.Get <IItemStorage>(); }
public static bool HasEmptySlots(this IItemStorage itemStorage) => itemStorage.Slots.ToList().Any(slot => slot.Empty);
protected void gvESPDocumentsList_RowCommand(object sender, GridViewCommandEventArgs e) { DocumentDAO docDao = new DocumentDAO(); string sTicket = (ConfigurationManager.AppSettings["espticket"] != null) ? ConfigurationManager.AppSettings["espticket"].ToString() : string.Empty; switch (e.CommandName) { case "preview": Session["ESPDocId"] = e.CommandArgument; using (DbDataReader dr = (DbDataReader)docDao.GetESPDocumentData(new Guid(e.CommandArgument.ToString()))) { if (dr.Read()) { lnkAddDocument.Visible = dr["idStatusu"].ToString().Equals("3"); docPreview.DocGuid = new Guid(e.CommandArgument.ToString()); } } break; case "download": ESPWebService ws = new ESPWebService(); if (ws != null) { Guid docGuid = new Guid(e.CommandArgument.ToString()); docDao.SetESPDocumentStatus(docGuid, DocumentDAO.ESPDocumentStatus.Downloading); try { string docId = docDao.GetESPDocId(docGuid); if (docId != string.Empty) { string docData = ws.GetDocument(sTicket, docId); if (docData.Contains("<error>")) { WebMsgBox.Show(this, "Błąd pobierania dokumentu ESP"); } else { byte[] data = Convert.FromBase64String(docData); ws.Dispose(); string xmlDoc = Encoding.UTF8.GetString(data); // pobranie XML i XSLT dokumentu XmlDocument doc = new XmlDocument(); doc.LoadXml(xmlDoc); data = Convert.FromBase64String(doc.SelectSingleNode("//Dokument[@typ='Dane']").InnerText); XmlDocument xmlData = new XmlDocument(); xmlData.LoadXml(Encoding.UTF8.GetString(data).Replace("UTF-8", "UTF-16").Replace("utf-8", "utf-16")); data = Convert.FromBase64String(doc.SelectSingleNode("//Dokument[@typ='Styl']").InnerText); XmlDocument xslData = new XmlDocument(); xslData.LoadXml(Encoding.UTF8.GetString(data).Replace("UTF-8", "UTF-16").Replace("utf-8", "utf-16")); IItemStorage storage = ItemStorageFactory.Create(); StringBuilder sb = new StringBuilder(); XmlWriter xw = XmlWriter.Create(sb); xw.WriteStartElement("zalaczniki"); foreach (XmlNode node in doc.SelectNodes("//Dokument[@typ='Zalacznik']")) { // dodawanie zalacznikow data = Convert.FromBase64String(node.InnerText); MemoryStream ms = new MemoryStream(data); Guid attachmentGuid = storage.Save(ms); xw.WriteStartElement("zalacznik"); xw.WriteAttributeString("id", attachmentGuid.ToString()); xw.WriteAttributeString("nazwa", node.Attributes["Nazwa"].Value); xw.WriteAttributeString("mime", node.Attributes["Mime"].Value); xw.WriteEndElement(); } xw.WriteEndElement(); xw.Close(); docDao.SetESPDocumentData(docGuid, xmlData.InnerXml, xslData.InnerXml, sb.ToString()); docDao.SetESPDocumentStatus(docGuid, DocumentDAO.ESPDocumentStatus.Downloaded); ws.ConfirmDocumentReceive(sTicket, docGuid.ToString()); gvESPDocumentsList.DataBind(); } } else { WebMsgBox.Show(this, "Nie można pobrać ID dokumentu ESP"); } } catch //(Exception ex) { docDao.SetESPDocumentStatus(docGuid, DocumentDAO.ESPDocumentStatus.Awaiting); } } break; default: docPreview.XmlData = string.Empty; lnkAddDocument.Visible = false; break; } }
public Guid Save(Stream itemContent) { IItemStorage storage = ItemStorageFactory.Create(); return(storage.Save(itemContent)); }
public ProductRestockDetailsWindow() { InitializeComponent(); itemStorage = new ItemMySQL(); }