/// <summary>
        ///A test for CryptDecodeObjectEx
        ///</summary>
        public void CryptDecodeObjectExTest()
        {
            Encodings dwCertEncodingType = new Encodings(); // TODO: Initialize to an appropriate value
            int lpszStructType = 0; // TODO: Initialize to an appropriate value
            byte[] pbEncoded = null; // TODO: Initialize to an appropriate value
            int cbEncoded = 0; // TODO: Initialize to an appropriate value
            int dwFlags = 0; // TODO: Initialize to an appropriate value
            IntPtr blah = new IntPtr(); // TODO: Initialize to an appropriate value
            CERT_PUBLIC_KEY_INFO pDecodePara = new CERT_PUBLIC_KEY_INFO(); // TODO: Initialize to an appropriate value
            CERT_PUBLIC_KEY_INFO pDecodeParaExpected = new CERT_PUBLIC_KEY_INFO(); // TODO: Initialize to an appropriate value
            int pcbStructInfo = 0; // TODO: Initialize to an appropriate value
            int pcbStructInfoExpected = 0; // TODO: Initialize to an appropriate value
            bool expected = false; // TODO: Initialize to an appropriate value

            var certInput = Resources.crud;
            var input = from a in certInput.Split(' ')
                        select Byte.Parse(a, System.Globalization.NumberStyles.HexNumber);
            bool actual;
            actual = PfxStoreLoader.CryptDecodeObjectEx((Encodings.PKCS_7_ASN_ENCODING | Encodings.X509_ASN_ENCODING), PfxStoreLoader.X509_PUBLIC_KEY_INFO,
                input.ToArray(), input.Count(), PfxStoreLoader.CRYPT_DECODE_ALLOC_FLAG, IntPtr.Zero, ref pDecodePara, ref pcbStructInfo);
            Assert.AreEqual(pDecodeParaExpected, pDecodePara);
            Assert.AreEqual(pcbStructInfoExpected, pcbStructInfo);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
 public StringGenerator()
 {
     name = string.Empty;
     StringLength = 0;
     CharacterSet = string.Empty;
     AllowRepetitions = false;
     Encoding = Encodings.None;
 }
 public CharacterGenerator()
 {
     name = string.Empty;
     StartCharacter = 0;
     StopCharacter = 0;
     Increment = 1;
     Encoding = Encodings.None;
 }
 public NumberGenerator()
 {
     name = string.Empty;
     StartNumber = 0;
     StopNumber = 0;
     Increment = 1;
     Encoding = Encodings.None;
 }
 public CharacterRepeater()
 {
     name = string.Empty;
     Character = string.Empty;
     InitialCount = 0;
     FinalCount = 0;
     Increment = 1;
     Encoding = Encodings.None;
 }
        public static int ReturnEncodingIndex(Encodings encodings)
        {
            if (encodings == Encodings.URL)
                return 1;
            else if (encodings == Encodings.URLComplete)
                return 2;
            else if (encodings == Encodings.Base64)
                return 3;
            else if (encodings == Encodings.MD5)
                return 4;

            return 0;
        }
示例#7
0
 public static Encoding GetEncoding(Encodings encoding)
 {
     return(Encoding.GetEncoding(Encodings[(int)encoding]));
 }
示例#8
0
 public StringDecoder(Encodings encodings)
 {
     Encodings = encodings;
 }
        public void SetEncoding(Encodings encodingType)
        {
            Encoding encoding = null;

            switch (encodingType)
            {
                //case Encodings.None:
                case Encodings.ASCII:
                    encoding = Encoding.ASCII;
                    break;
                case Encodings.UTF7:
                    encoding = Encoding.UTF7;
                    break;
                case Encodings.UTF8:
                    encoding = Encoding.UTF8;
                    break;
            }

            string clearText = GenerateClearText();

            string key = GeneratePassPhrase();

            ICryptoEngine engine = new RC2Engine(key)
                .SetEncoding(encoding);

            string encrypted = engine.Encrypt(clearText);
            string decrypted = engine.Decrypt(encrypted);

            Assert.NotEqual(clearText, encrypted);
            Assert.Equal(clearText, decrypted);
        }
示例#10
0
 /// <summary>
 /// Converts to a list of boolean about areas.
 /// </summary>
 /// <param name="encoding">The encoding.</param>
 /// <returns>The areas. White represented as false, black represented as true.</returns>
 /// <exception cref="InvalidOperationException">encoding is not valid.</exception>
 public List <bool> ToList(Encodings encoding)
 => encoding switch
 {
        private void ProcessOptPrices(string optPricesFilePath)
        {
            using (var csv = new CsvHelper.CsvReader(new StreamReader(optPricesFilePath, Encoding.UTF8)))// Encodings.GetEncoding())))
            {
                LogInvalidData(string.Format("ProcessOptPrices Start 1: Encoding: {0}, File: {1}, Time: {2}", Encodings.GetEncoding(), optPricesFilePath, DateTime.Now));

                csv.Configuration.Delimiter       = Separators.GetCharSeparator();
                csv.Configuration.HasHeaderRecord = true;
                Product product;

                bool firstRead = true;

                //      LogInvalidData(string.Format("ProcessOptPrices Start 2: Encoding: {0}, File: {1}, Time: {2}", Encodings.GetEncoding(), optPricesFilePath, DateTime.Now));

                while (csv.Read())
                {
                    try
                    {
                        //           LogInvalidData(string.Format("ProcessOptPrices Start 3: csv: {0}, File: {1}, Time: {2}", Encodings.GetEncoding(), optPricesFilePath, DateTime.Now));
                        if (firstRead)
                        {
                            for (int i = 0; i < csv.FieldHeaders.Length; i++)
                            {
                                FieldMapping.Add(csv.FieldHeaders[i], i);
                            }
                            firstRead = false;
                        }

                        //           LogInvalidData(string.Format("ProcessOptPrices Start 4: csv: {0}, File: {1}, Time: {2}", Encodings.GetEncoding(), optPricesFilePath, DateTime.Now));


                        var productInStrings = new Dictionary <ProductFields.Fields, string>();

                        string artNo = ProductFields.GetStringNameByEnum(ProductFields.Fields.Sku);
                        if (FieldMapping.ContainsKey(artNo))
                        {
                            productInStrings.Add(ProductFields.Fields.Sku, Convert.ToString(csv[FieldMapping[artNo]]));
                        }

                        //sku;amount;priceOpt1;priceOpt2;priceAkc1;priceAkc2;priceSpec;priceEur

                        product = ProductService.GetProduct(Convert.ToString(csv[FieldMapping[artNo]]));
                        decimal priceOpt1;
                        decimal priceOpt2;

                        decimal priceAkc1;
                        decimal priceAkc2;

                        decimal priceSpec;
                        decimal priceEur;

                        decimal.TryParse(csv["priceOpt1"].ToString().Replace(" ", ""), out priceOpt1);
                        decimal.TryParse(csv["priceOpt2"].ToString().Replace(" ", ""), out priceOpt2);
                        decimal.TryParse(csv["priceAkc1"].ToString().Replace(" ", ""), out priceAkc1);
                        decimal.TryParse(csv["priceAkc2"].ToString().Replace(" ", ""), out priceAkc2);
                        decimal.TryParse(csv["priceSpec"].ToString().Replace(" ", ""), out priceSpec);

                        decimal.TryParse(csv["priceEur"].ToString().Replace(" ", ""), out priceEur);
                        if (priceEur == 0 && csv["priceEur"].ToString().Contains("."))
                        {
                            decimal.TryParse(csv["priceEur"].ToString().Replace(" ", "").Replace(".", ","), out priceEur);
                        }
                        string briefDescription = csv["BriefDescription"].ToString();
                        product.BriefDescription = briefDescription;

                        product.Offers.Add(new Offer
                        {
                            Amount        = product.Offers[0].Amount,
                            OfferListId   = 9,
                            Price         = priceOpt1,
                            ShippingPrice = 0,
                            SupplyPrice   = 0,
                            Unit          = product.Offers[0].Unit,
                            Multiplicity  = product.Offers[0].Multiplicity
                        });

                        product.Offers.Add(new Offer
                        {
                            Amount        = product.Offers[0].Amount,
                            OfferListId   = 12,
                            Price         = priceOpt2,
                            ShippingPrice = 0,
                            SupplyPrice   = 0,
                            Unit          = product.Offers[0].Unit,
                            Multiplicity  = product.Offers[0].Multiplicity
                        });

                        product.Offers.Add(new Offer
                        {
                            Amount        = product.Offers[0].Amount,
                            OfferListId   = 13,
                            Price         = priceAkc1,
                            ShippingPrice = 0,
                            SupplyPrice   = 0,
                            Unit          = product.Offers[0].Unit,
                            Multiplicity  = product.Offers[0].Multiplicity
                        });

                        product.Offers.Add(new Offer
                        {
                            Amount        = product.Offers[0].Amount,
                            OfferListId   = 14,
                            Price         = priceAkc2,
                            ShippingPrice = 0,
                            SupplyPrice   = 0,
                            Unit          = product.Offers[0].Unit,
                            Multiplicity  = product.Offers[0].Multiplicity
                        });

                        product.Offers.Add(new Offer
                        {
                            Amount        = product.Offers[0].Amount,
                            OfferListId   = 15,
                            Price         = priceSpec,
                            ShippingPrice = 0,
                            SupplyPrice   = 0,
                            Unit          = product.Offers[0].Unit,
                            Multiplicity  = product.Offers[0].Multiplicity
                        });

                        product.Offers.Add(new Offer
                        {
                            Amount        = product.Offers[0].Amount,
                            OfferListId   = 16,
                            Price         = priceEur,
                            ShippingPrice = 0,
                            SupplyPrice   = 0,
                            Unit          = product.Offers[0].Unit,
                            Multiplicity  = product.Offers[0].Multiplicity
                        });

                        //            LogInvalidData(string.Format("ProcessOptPrices Start 5: csv: {0}, File: {1}, Time: {2}", product.ArtNo, optPricesFilePath, DateTime.Now));

                        ProductService.UpdateProduct(product, false);

                        //             LogInvalidData(string.Format("ProcessOptPrices Start 6: csv: {0}, File: {1}, Time: {2}", product.ArtNo, optPricesFilePath, DateTime.Now));
                    }
                    catch (Exception ex)
                    {
                        LogInvalidData("Ex  " + ex.Message + DateTime.Now.ToString());
                    }
                }
            }
            try
            {
                File.Copy(optPricesFilePath, optPricesFilePath.Replace("OstatkiWseCeny.csv", string.Format("OstatkiWseCeny_done{0}.csv", DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss"))));
                FileHelpers.DeleteFile(optPricesFilePath);
            }
            catch (Exception ex)
            {
                LogInvalidData("Ex File.Copy(...  " + ex.Message + DateTime.Now.ToString());
            }
        }
示例#12
0
 /// <summary>
 /// Sets the encoding in which the file will be interpreted upon reading it from the disc.
 /// To see a change in the representation, the content needs to be read again.
 /// </summary>
 /// <param name="type">The given type of input encoding.</param>
 public void SetInputEncoding(EncodingType type)
 {
     InputEncoding = Encodings.GetEncoding(type);
 }
示例#13
0
 public ResponseHeader(ContentTypes contentType) : base()
 {
     ResponseCode = ResponseCodes.OK; ContentType = contentType; Encoding = Encodings.UTF8;
 }
示例#14
0
 public Class953(ushort dwgCodePage, DrawingCodePage drawingCodePage)
 {
     this.ushort_0          = dwgCodePage;
     this.drawingCodePage_0 = drawingCodePage;
     this.encoding_0        = Encodings.GetEncoding((int)drawingCodePage);
 }
示例#15
0
文件: Class653.cs 项目: 15831944/WW
        private void method_12()
        {
            int          sectionStartPosition1 = (int)Class653.smethod_0(this.int_0);
            int          num1 = sectionStartPosition1 + (int)this.memoryStream_0.Length;
            int          sectionStartPosition2 = num1 + (int)this.memoryStream_4.Length;
            int          sectionStartPosition3 = sectionStartPosition2 + (int)this.memoryStream_1.Length;
            int          sectionStartPosition4 = sectionStartPosition3 + (int)this.memoryStream_2.Length + (int)this.memoryStream_3.Length + (int)this.memoryStream_5.Length;
            int          sectionStartPosition5 = sectionStartPosition4 + (int)this.memoryStream_6.Length + (int)this.memoryStream_7.Length;
            MemoryStream memoryStream          = new MemoryStream();
            Interface29  streamWriter          = Class724.Create(this.dxfVersion_0, (Stream)memoryStream, Encodings.GetEncoding((int)this.dxfModel_0.Header.DrawingCodePage));

            streamWriter.imethod_13(Encodings.Ascii.GetBytes(this.dxfModel_0.Header.AcadVersionString), 0, 6);
            Interface29 nterface29 = streamWriter;

            byte[] numArray = new byte[7];
            numArray[5] = (byte)15;
            numArray[6] = (byte)1;
            byte[] bytes = numArray;
            nterface29.imethod_12(bytes);
            streamWriter.imethod_19(num1);
            streamWriter.imethod_11((byte)27);
            streamWriter.imethod_11((byte)25);
            int num2 = (int)Class952.smethod_1(this.dxfModel_0.Header.DrawingCodePage);

            streamWriter.imethod_13(LittleEndianBitConverter.GetBytes((short)num2), 0, 2);
            streamWriter.imethod_13(LittleEndianBitConverter.GetBytes(this.int_0), 0, 4);
            long position = this.stream_0.Position;

            this.method_13(streamWriter, (byte)0, sectionStartPosition2, (int)this.memoryStream_1.Length);
            this.method_13(streamWriter, (byte)1, sectionStartPosition3, (int)this.memoryStream_2.Length);
            this.method_13(streamWriter, (byte)2, sectionStartPosition4, (int)this.memoryStream_6.Length);
            this.method_13(streamWriter, (byte)3, 0, 0);
            this.method_13(streamWriter, (byte)4, sectionStartPosition5, (int)this.memoryStream_9.Length);
            this.method_13(streamWriter, (byte)5, sectionStartPosition1, (int)this.memoryStream_0.Length);
            streamWriter.Flush();
            ushort num3 = Stream1.smethod_1((ushort)49345, memoryStream.GetBuffer(), 0L, memoryStream.Length);

            streamWriter.imethod_18((short)num3);
            streamWriter.imethod_13(Class800.byte_4, 0, Class800.byte_4.Length);
            this.stream_0.Write(memoryStream.GetBuffer(), 0, (int)memoryStream.Length);
        }
 public FileGenerator()
 {
     name = string.Empty;
     FilePath = string.Empty;
     Encoding = Encodings.None;
 }
示例#17
0
        public string ToString(Encodings encodings)
        {
            IItem item = encodings[ItemUID] as IItem;

            return(item.ToString(Rate.ToDecimal()) + " " + item.DisplayName);
        }
示例#18
0
    private void ProcessCsv()
    {
        if (chboxDisableProducts.Checked)
        {
            ProductService.DisableAllProducts();
        }

        long count = 0;

        using (var csv = new CsvHelper.CsvReader(new StreamReader(_fullPath, Encodings.GetEncoding())))
        {
            csv.Configuration.Delimiter       = Separators.GetCharSeparator();
            csv.Configuration.HasHeaderRecord = _hasHeadrs;
            while (csv.Read())
            {
                count++;
            }
        }

        ImportStatistic.TotalRow = count;

        using (var csv = new CsvHelper.CsvReader(new StreamReader(_fullPath, Encodings.GetEncoding())))
        {
            csv.Configuration.Delimiter       = Separators.GetCharSeparator();
            csv.Configuration.HasHeaderRecord = _hasHeadrs;

            while (csv.Read())
            {
                if (!ImportStatistic.IsRun)
                {
                    csv.Dispose();
                    FileHelpers.DeleteFile(_fullPath);
                    return;
                }
                try
                {
                    //Added by Evgeni to Remove dots
                    //   csv.CurrentRecord[0] = csv.CurrentRecord[0].Replace(".", "").Replace(" ", "");
                    // Step by rows
                    var productInStrings = new Dictionary <ProductFields.Fields, string>();

                    string nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Sku);
                    if (FieldMapping.ContainsKey(nameField))
                    {
                        productInStrings.Add(ProductFields.Fields.Sku, Convert.ToString(csv[FieldMapping[nameField]]));
                    }

                    nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Name).Trim('*');
                    if (FieldMapping.ContainsKey(nameField))
                    {
                        var name = Convert.ToString(csv[FieldMapping[nameField]]);
                        if (!string.IsNullOrEmpty(name))
                        {
                            productInStrings.Add(ProductFields.Fields.Name, name);
                        }
                        else
                        {
                            LogInvalidData(string.Format(Resource.Admin_ImportCsv_CanNotEmpty, ProductFields.GetDisplayNameByEnum(ProductFields.Fields.Name), ImportStatistic.RowPosition + 2));
                            continue;
                        }
                    }

                    nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Enabled).Trim('*');
                    if (FieldMapping.ContainsKey(nameField))
                    {
                        string enabled = Convert.ToString(csv[FieldMapping[nameField]]);
                        productInStrings.Add(ProductFields.Fields.Enabled, enabled);
                        //product.Enabled = !string.IsNullOrEmpty(enabled) && enabled.Trim().Equals("+");
                    }

                    nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Discount);
                    if (FieldMapping.ContainsKey(nameField))
                    {
                        var discount = Convert.ToString(csv[FieldMapping[nameField]]);
                        if (string.IsNullOrEmpty(discount))
                        {
                            discount = "0";
                        }
                        decimal tmp;
                        if (decimal.TryParse(discount, out tmp))
                        {
                            productInStrings.Add(ProductFields.Fields.Discount, tmp.ToString());
                        }
                        else if (decimal.TryParse(discount, NumberStyles.Any, CultureInfo.InvariantCulture, out tmp))
                        {
                            productInStrings.Add(ProductFields.Fields.Discount, tmp.ToString());
                        }
                        else
                        {
                            LogInvalidData(string.Format(Resource.Admin_ImportCsv_MustBeNumber, ProductFields.GetDisplayNameByEnum(ProductFields.Fields.Discount), ImportStatistic.RowPosition + 2));
                            continue;
                        }
                    }

                    nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Weight);
                    if (FieldMapping.ContainsKey(nameField))
                    {
                        var weight = Convert.ToString(csv[FieldMapping[nameField]]);
                        if (string.IsNullOrEmpty(weight))
                        {
                            weight = "0";
                        }
                        decimal tmp;
                        if (decimal.TryParse(weight, out tmp))
                        {
                            productInStrings.Add(ProductFields.Fields.Weight, tmp.ToString());
                        }
                        else if (decimal.TryParse(weight, NumberStyles.Any, CultureInfo.InvariantCulture, out tmp))
                        {
                            productInStrings.Add(ProductFields.Fields.Weight, tmp.ToString());
                        }
                        else
                        {
                            LogInvalidData(string.Format(Resource.Admin_ImportCsv_MustBeNumber, ProductFields.GetDisplayNameByEnum(ProductFields.Fields.Weight), ImportStatistic.RowPosition + 2));
                            continue;
                        }
                    }

                    nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Size);
                    if (FieldMapping.ContainsKey(nameField))
                    {
                        productInStrings.Add(ProductFields.Fields.Size, Convert.ToString(csv[FieldMapping[nameField]]));
                    }

                    nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.BriefDescription);
                    if (FieldMapping.ContainsKey(nameField))
                    {
                        productInStrings.Add(ProductFields.Fields.BriefDescription, Convert.ToString(csv[FieldMapping[nameField]]));
                    }

                    nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Description);
                    if (FieldMapping.ContainsKey(nameField))
                    {
                        productInStrings.Add(ProductFields.Fields.Description, Convert.ToString(csv[FieldMapping[nameField]]));
                    }

                    nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Price).Trim('*');
                    if (FieldMapping.ContainsKey(nameField))
                    {
                        var price = Convert.ToString(csv[FieldMapping[nameField]]);
                        if (string.IsNullOrEmpty(price))
                        {
                            price = "0";
                        }
                        decimal tmp;
                        if (decimal.TryParse(price, out tmp))
                        {
                            productInStrings.Add(ProductFields.Fields.Price, tmp.ToString());
                        }
                        else if (decimal.TryParse(price, NumberStyles.Any, CultureInfo.InvariantCulture, out tmp))
                        {
                            productInStrings.Add(ProductFields.Fields.Price, tmp.ToString());
                        }
                        else
                        {
                            LogInvalidData(string.Format(Resource.Admin_ImportCsv_MustBeNumber, ProductFields.GetDisplayNameByEnum(ProductFields.Fields.Price), ImportStatistic.RowPosition + 2));
                            continue;
                        }
                    }

                    nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.PurchasePrice);
                    if (FieldMapping.ContainsKey(nameField))
                    {
                        var sypplyprice = Convert.ToString(csv[FieldMapping[nameField]]);
                        if (string.IsNullOrEmpty(sypplyprice))
                        {
                            sypplyprice = "0";
                        }
                        decimal tmp;
                        if (decimal.TryParse(sypplyprice, out tmp))
                        {
                            productInStrings.Add(ProductFields.Fields.PurchasePrice, tmp.ToString());
                        }
                        else if (decimal.TryParse(sypplyprice, NumberStyles.Any, CultureInfo.InvariantCulture, out tmp))
                        {
                            productInStrings.Add(ProductFields.Fields.PurchasePrice, tmp.ToString());
                        }
                        else
                        {
                            LogInvalidData(string.Format(Resource.Admin_ImportCsv_MustBeNumber, ProductFields.GetDisplayNameByEnum(ProductFields.Fields.PurchasePrice), ImportStatistic.RowPosition + 2));
                            continue;
                        }
                    }

                    nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.ShippingPrice);
                    if (FieldMapping.ContainsKey(nameField))
                    {
                        var shippingPrice = Convert.ToString(csv[FieldMapping[nameField]]);
                        if (string.IsNullOrEmpty(shippingPrice))
                        {
                            shippingPrice = "0";
                        }
                        decimal tmp;
                        if (decimal.TryParse(shippingPrice, out tmp))
                        {
                            productInStrings.Add(ProductFields.Fields.ShippingPrice, tmp.ToString());
                        }
                        else if (decimal.TryParse(shippingPrice, NumberStyles.Any, CultureInfo.InvariantCulture, out tmp))
                        {
                            productInStrings.Add(ProductFields.Fields.ShippingPrice, tmp.ToString());
                        }
                        else
                        {
                            LogInvalidData(string.Format(Resource.Admin_ImportCsv_MustBeNumber, ProductFields.GetDisplayNameByEnum(ProductFields.Fields.ShippingPrice), ImportStatistic.RowPosition + 2));
                            continue;
                        }
                    }

                    nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Amount);
                    if (FieldMapping.ContainsKey(nameField))
                    {
                        var amount = Convert.ToString(csv[FieldMapping[nameField]]);
                        if (string.IsNullOrEmpty(amount))
                        {
                            amount = "0";
                        }
                        int tmp;
                        if (int.TryParse(amount, out tmp))
                        {
                            productInStrings.Add(ProductFields.Fields.Amount, amount);
                        }
                        else
                        {
                            LogInvalidData(string.Format(Resource.Admin_ImportCsv_MustBeNumber, ProductFields.GetDisplayNameByEnum(ProductFields.Fields.Amount), ImportStatistic.RowPosition + 2));
                            continue;
                        }
                    }

                    nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Unit);
                    if (FieldMapping.ContainsKey(nameField))
                    {
                        productInStrings.Add(ProductFields.Fields.Unit, Convert.ToString(csv[FieldMapping[nameField]]));
                    }

                    nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.ParamSynonym);
                    if (FieldMapping.ContainsKey(nameField))
                    {
                        string rewurl = Convert.ToString(csv[FieldMapping[nameField]]);
                        productInStrings.Add(ProductFields.Fields.ParamSynonym, rewurl);
                    }

                    nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Title);
                    if (FieldMapping.ContainsKey(nameField))
                    {
                        productInStrings.Add(ProductFields.Fields.Title, Convert.ToString(csv[FieldMapping[nameField]]));
                    }

                    nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.MetaKeywords);
                    if (FieldMapping.ContainsKey(nameField))
                    {
                        productInStrings.Add(ProductFields.Fields.MetaKeywords, Convert.ToString(csv[FieldMapping[nameField]]));
                    }

                    nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.MetaDescription);
                    if (FieldMapping.ContainsKey(nameField))
                    {
                        productInStrings.Add(ProductFields.Fields.MetaDescription, Convert.ToString(csv[FieldMapping[nameField]]));
                    }

                    nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Photos);
                    if (FieldMapping.ContainsKey(nameField))
                    {
                        productInStrings.Add(ProductFields.Fields.Photos, Convert.ToString(csv[FieldMapping[nameField]]));
                    }

                    nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Markers);
                    if (FieldMapping.ContainsKey(nameField))
                    {
                        productInStrings.Add(ProductFields.Fields.Markers, Convert.ToString(csv[FieldMapping[nameField]]));
                    }

                    nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Properties);
                    if (FieldMapping.ContainsKey(nameField))
                    {
                        productInStrings.Add(ProductFields.Fields.Properties, Convert.ToString(csv[FieldMapping[nameField]]));
                    }

                    nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Producer);
                    if (FieldMapping.ContainsKey(nameField))
                    {
                        productInStrings.Add(ProductFields.Fields.Producer, Convert.ToString(csv[FieldMapping[nameField]]));
                    }

                    nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.OrderByRequest);
                    if (FieldMapping.ContainsKey(nameField))
                    {
                        string orderbyrequest = Convert.ToString(csv[FieldMapping[nameField]]);
                        productInStrings.Add(ProductFields.Fields.OrderByRequest, orderbyrequest);
                    }

                    nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Category).Trim('*');
                    if (FieldMapping.ContainsKey(nameField))
                    {
                        var parentCategory = Convert.ToString(csv[FieldMapping[nameField]]);
                        if (!string.IsNullOrEmpty(parentCategory))
                        {
                            productInStrings.Add(ProductFields.Fields.Category, parentCategory);
                        }
                    }

                    ImportProduct.UpdateInsertProduct(productInStrings);
                }
                catch (Exception ex)
                {
                    MsgErr(ex.Message + " at csv");
                    Debug.LogError(ex);
                }
            }
            CategoryService.RecalculateProductsCountManual();
        }
        ImportStatistic.IsRun = false;
        LuceneSearch.CreateAllIndexInBackground();
        CacheManager.Clean();
        FileHelpers.DeleteFilesFromImageTempInBackground();
        FileHelpers.DeleteFile(_fullPath);
    }
示例#19
0
    protected void Page_Init(object sender, EventArgs e)
    {
        MsgErr(true);

        divStart.Visible  = !ImportStatistic.IsRun && (string.IsNullOrEmpty(Request["action"]));
        divAction.Visible = !ImportStatistic.IsRun && (Request["action"] == "start");

        choseDiv.Visible = !ImportStatistic.IsRun;

        OutDiv.Visible     = ImportStatistic.IsRun;
        linkCancel.Visible = ImportStatistic.IsRun;

        if (ImportStatistic.IsRun || (Request["action"] != "start"))
        {
            return;
        }
        if (!File.Exists(_fullPath))
        {
            return;
        }

        var tbl = new Table()
        {
            ID = "tblValues"
        };
        var namesRow = new TableRow {
            ID = "namesRow", BackColor = System.Drawing.ColorTranslator.FromHtml("#0D76B8")
        };
        var firstValRow = new TableRow {
            ID = "firstValsRow"
        };
        var ddlRow = new TableRow {
            ID = "ddlRow"
        };

        var firstCell = new TableCell {
            Width = 200, BackColor = System.Drawing.Color.White,
        };

        firstCell.Controls.Add(new Label {
            Text = Resources.Resource.Admin_ImportCsv_Column, CssClass = "firstColumn"
        });
        var div1 = new Panel {
            CssClass = "arrow_left_bg"
        };

        div1.Controls.Add(new Panel {
            CssClass = "arrow_right_bg"
        });
        firstCell.Controls.Add(div1);


        var secondCell = new TableCell {
            Width = 200
        };

        secondCell.Controls.Add(new Label {
            Text = Resources.Resource.Admin_ImportCsv_FistLineInTheFile, CssClass = "firstColumn"
        });
        var div2 = new Panel {
            CssClass = "arrow_left_bg_two"
        };

        div2.Controls.Add(new Panel {
            CssClass = "arrow_right_bg"
        });
        secondCell.Controls.Add(div2);

        var firdCell = new TableCell {
            Width = 200
        };

        firdCell.Controls.Add(new Label {
            Text = Resources.Resource.Admin_ImportCsv_DataType, CssClass = "firstColumn"
        });
        var div3 = new Panel {
            CssClass = "arrow_left_bg_free"
        };

        div3.Controls.Add(new Panel {
            CssClass = "arrow_right_bg"
        });
        firdCell.Controls.Add(div3);
        var div4 = new Panel {
            Width = 200
        };

        firdCell.Controls.Add(div4);

        namesRow.Cells.Add(firstCell);
        firstValRow.Cells.Add(secondCell);
        ddlRow.Cells.Add(firdCell);

        _hasHeadrs = chbHasHeadrs.Checked;
        using (var csv = new CsvHelper.CsvReader(new StreamReader(_fullPath, Encodings.GetEncoding())))
        {
            csv.Configuration.Delimiter       = Separators.GetCharSeparator();
            csv.Configuration.BufferSize      = 0x1000;
            csv.Configuration.HasHeaderRecord = false;

            csv.Read();

            if (_hasHeadrs && csv.CurrentRecord.HasDuplicates())
            {
                var strFileds = string.Empty;
                foreach (var item in csv.CurrentRecord.Duplicates())
                {
                    strFileds += "\"" + item + "\",";
                }
                MsgErr(Resource.Admin_ImportCsv_DuplicateHeader + strFileds.Trim(','));
                btnAction.Visible = false;
            }

            for (int i = 0; i < csv.CurrentRecord.Length; i++)
            {
                //Added by Evgeni to Import csv with dotes
                // csv.CurrentRecord[0] = csv.CurrentRecord[0].Replace(".", "").Replace(" ", "");

                var cell = new TableCell {
                    ID = "cell" + i.ToString()
                };
                var  lb = new Label();
                bool flagMustReqField = false;
                if (Request["hasheadrs"].ToLower() == "true")
                {
                    var tempCsv = (csv[i].Length > 50 ? csv[i].Substring(0, 49) : csv[i]).Replace("*", "");
                    if (_mustRequiredFfield.Any(item => ProductFields.GetStringNameByEnum(item).Replace("*", "") == tempCsv.ToLower()))
                    {
                        flagMustReqField = true;
                    }
                    lb.Text = tempCsv;
                }
                else
                {
                    lb.Text = Resource.Admin_ImportCsv_Empty;
                }
                lb.ForeColor = System.Drawing.Color.White;
                cell.Controls.Add(lb);

                if (flagMustReqField)
                {
                    var lbl = new Label
                    {
                        Text      = @"*",
                        ForeColor = System.Drawing.Color.Red
                    };
                    cell.Controls.Add(lbl);
                }

                namesRow.Cells.Add(cell);

                cell = new TableCell()
                {
                    Width = 150
                };
                var ddl = new DropDownList {
                    ID = "ddlType" + i.ToString(), Width = 150
                };
                ddl.Items.Add(new ListItem(ProductFields.GetDisplayNameByEnum(ProductFields.Fields.None), ProductFields.GetStringNameByEnum(ProductFields.Fields.None)));
                ddl.Items.Add(new ListItem(ProductFields.GetDisplayNameByEnum(ProductFields.Fields.Sku), ProductFields.GetStringNameByEnum(ProductFields.Fields.Sku)));
                ddl.Items.Add(new ListItem(ProductFields.GetDisplayNameByEnum(ProductFields.Fields.Name), ProductFields.GetStringNameByEnum(ProductFields.Fields.Name).Trim('*')));
                ddl.Items.Add(new ListItem(ProductFields.GetDisplayNameByEnum(ProductFields.Fields.ParamSynonym), ProductFields.GetStringNameByEnum(ProductFields.Fields.ParamSynonym)));
                ddl.Items.Add(new ListItem(ProductFields.GetDisplayNameByEnum(ProductFields.Fields.Category), ProductFields.GetStringNameByEnum(ProductFields.Fields.Category).Trim('*')));
                ddl.Items.Add(new ListItem(ProductFields.GetDisplayNameByEnum(ProductFields.Fields.Enabled), ProductFields.GetStringNameByEnum(ProductFields.Fields.Enabled).Trim('*')));
                ddl.Items.Add(new ListItem(ProductFields.GetDisplayNameByEnum(ProductFields.Fields.Price), ProductFields.GetStringNameByEnum(ProductFields.Fields.Price).Trim('*')));
                ddl.Items.Add(new ListItem(ProductFields.GetDisplayNameByEnum(ProductFields.Fields.PurchasePrice), ProductFields.GetStringNameByEnum(ProductFields.Fields.PurchasePrice)));
                ddl.Items.Add(new ListItem(ProductFields.GetDisplayNameByEnum(ProductFields.Fields.Amount), ProductFields.GetStringNameByEnum(ProductFields.Fields.Amount)));
                ddl.Items.Add(new ListItem(ProductFields.GetDisplayNameByEnum(ProductFields.Fields.Unit), ProductFields.GetStringNameByEnum(ProductFields.Fields.Unit)));
                ddl.Items.Add(new ListItem(ProductFields.GetDisplayNameByEnum(ProductFields.Fields.Discount), ProductFields.GetStringNameByEnum(ProductFields.Fields.Discount)));
                ddl.Items.Add(new ListItem(ProductFields.GetDisplayNameByEnum(ProductFields.Fields.ShippingPrice), ProductFields.GetStringNameByEnum(ProductFields.Fields.ShippingPrice)));
                ddl.Items.Add(new ListItem(ProductFields.GetDisplayNameByEnum(ProductFields.Fields.Weight), ProductFields.GetStringNameByEnum(ProductFields.Fields.Weight)));
                ddl.Items.Add(new ListItem(ProductFields.GetDisplayNameByEnum(ProductFields.Fields.Size), ProductFields.GetStringNameByEnum(ProductFields.Fields.Size)));
                ddl.Items.Add(new ListItem(ProductFields.GetDisplayNameByEnum(ProductFields.Fields.BriefDescription), ProductFields.GetStringNameByEnum(ProductFields.Fields.BriefDescription)));
                ddl.Items.Add(new ListItem(ProductFields.GetDisplayNameByEnum(ProductFields.Fields.Description), ProductFields.GetStringNameByEnum(ProductFields.Fields.Description)));

                ddl.Items.Add(new ListItem(ProductFields.GetDisplayNameByEnum(ProductFields.Fields.Title), ProductFields.GetStringNameByEnum(ProductFields.Fields.Title)));
                ddl.Items.Add(new ListItem(ProductFields.GetDisplayNameByEnum(ProductFields.Fields.MetaKeywords), ProductFields.GetStringNameByEnum(ProductFields.Fields.MetaKeywords)));
                ddl.Items.Add(new ListItem(ProductFields.GetDisplayNameByEnum(ProductFields.Fields.MetaDescription), ProductFields.GetStringNameByEnum(ProductFields.Fields.MetaDescription)));
                ddl.Items.Add(new ListItem(ProductFields.GetDisplayNameByEnum(ProductFields.Fields.Photos), ProductFields.GetStringNameByEnum(ProductFields.Fields.Photos)));
                ddl.Items.Add(new ListItem(ProductFields.GetDisplayNameByEnum(ProductFields.Fields.Markers), ProductFields.GetStringNameByEnum(ProductFields.Fields.Markers)));
                ddl.Items.Add(new ListItem(ProductFields.GetDisplayNameByEnum(ProductFields.Fields.Properties), ProductFields.GetStringNameByEnum(ProductFields.Fields.Properties)));
                ddl.Items.Add(new ListItem(ProductFields.GetDisplayNameByEnum(ProductFields.Fields.Producer), ProductFields.GetStringNameByEnum(ProductFields.Fields.Producer)));
                ddl.Items.Add(new ListItem(ProductFields.GetDisplayNameByEnum(ProductFields.Fields.OrderByRequest), ProductFields.GetStringNameByEnum(ProductFields.Fields.OrderByRequest)));

                ddl.SelectedValue = lb.Text.Replace("*", "").Trim().ToLower();
                cell.Controls.Add(ddl);
                ddlRow.Cells.Add(cell);
            }

            csv.Read();
            if (csv.CurrentRecord != null)
            {
                for (int i = 0; i < csv.CurrentRecord.Length; i++)
                {
                    //Added by Evgeni to remove dots
                    //csv.CurrentRecord[0] = csv.CurrentRecord[0].Replace(".", "").Replace(" ", "");

                    var cell = new TableCell();
                    if (csv[i] == null)
                    {
                        cell.Controls.Add(new Label {
                            Text = string.Empty
                        });
                    }
                    else
                    {
                        cell.Controls.Add(new Label {
                            Text = csv[i].Length > 50 ? csv[i].Substring(0, 49).HtmlEncode() : csv[i].HtmlEncode()
                        });
                    }
                    firstValRow.Cells.Add(cell);
                }
            }
        }
        tbl.Rows.Add(namesRow);
        tbl.Rows.Add(firstValRow);
        tbl.Rows.Add(ddlRow);
        choseDiv.Controls.Add(tbl);
    }
示例#20
0
 public ResponseHeader(Header baseHeader) : base(baseHeader ?? new Header())
 {
     ResponseCode = ResponseCodes.OK; ContentType = ContentTypes.TEXTHTML; Encoding = Encodings.UTF8;
 }
示例#21
0
 public ResponseHeader(Header baseHeader, ContentTypes contentType) : base(baseHeader ?? new Header())
 {
     ResponseCode = ResponseCodes.OK; ContentType = contentType; Encoding = Encodings.UTF8;
 }
示例#22
0
        public static int EncodeHeader(System.IO.Stream buffer, PacketTypes type, Flags1 flags1, Flags2 flags2, Encodings encoding, UInt16 serial_high_low, Guid object_id, Guid interface_id, Guid activity_id, UInt32 server_boot_time, UInt32 sequence_no, Operations op, UInt16 body_length, UInt16 fragment_no, out long body_length_position)
        {
            int ret = 0;

            ret += DCP.EncodeU8(buffer, 4);             //RPCVersion
            ret += DCP.EncodeU8(buffer, (byte)type);
            ret += DCP.EncodeU8(buffer, (byte)flags1);
            ret += DCP.EncodeU8(buffer, (byte)flags2);
            ret += DCP.EncodeU16(buffer, (ushort)encoding);
            ret += DCP.EncodeU8(buffer, 0);             //pad
            ret += DCP.EncodeU8(buffer, (byte)(serial_high_low >> 8));
            ret += EncodeGuid(buffer, encoding, object_id);
            ret += EncodeGuid(buffer, encoding, interface_id);
            ret += EncodeGuid(buffer, encoding, activity_id);
            ret += EncodeU32(buffer, encoding, server_boot_time);
            ret += EncodeU32(buffer, encoding, 1);               //interface version
            ret += EncodeU32(buffer, encoding, sequence_no);
            ret += EncodeU16(buffer, encoding, (ushort)op);
            ret += EncodeU16(buffer, encoding, 0xFFFF);                 //interface hint
            ret += EncodeU16(buffer, encoding, 0xFFFF);                 //activity hint
            body_length_position = buffer.Position;
            ret += EncodeU16(buffer, encoding, body_length);
            ret += EncodeU16(buffer, encoding, fragment_no);
            ret += DCP.EncodeU8(buffer, 0);             //authentication protocol
            ret += DCP.EncodeU8(buffer, (byte)(serial_high_low & 0xFF));

            return(ret);
        }
        private void serviceInstaller_AfterInstall(object sender, InstallEventArgs e)
        {
            //MessageBox.Show("Called AfterInstall");

            // Restore the history file from the %HOMEPATH% if it exists
            string installPath = Context.Parameters["TARGETDIR"].Replace(@"\\", @"\").Trim();

            try
            {
                // Copy the backup files back to the MCEBuddy installation directory with .old extensions (except history)
                // Convert History file to unicode while copying it back
                if (File.Exists(Path.Combine(Environment.GetEnvironmentVariable("HOMEPATH"), "history")))
                {
                    string sourceHistory      = Path.Combine(Environment.GetEnvironmentVariable("HOMEPATH"), "history");
                    string destinationHistory = Path.Combine(installPath, @"config\history");

                    // First check if the file is a UTF16LE file (required for INI files)
                    if (Encodings.GetFileEncoding(sourceHistory) != Encoding.Unicode)
                    {
                        using (StreamReader sourceRead = new StreamReader(sourceHistory))                                                   // Open the source file for reading
                        {
                            FileIO.TryFileDelete(destinationHistory);                                                                       // Try to delete the destination file first
                            using (FileStream destinationFile = File.Create(destinationHistory))                                            // Create the destination file
                            {
                                using (StreamWriter destinationWrite = new StreamWriter(destinationFile, new UnicodeEncoding(false, true))) // UTF16, LE with BOM for INI files
                                {
                                    // Read everything from the file
                                    string line;
                                    while ((line = sourceRead.ReadLine()) != null)
                                    {
                                        destinationWrite.WriteLine(line); // Write to the new file
                                    }
                                    destinationWrite.Close();
                                }
                                destinationFile.Close();
                            }
                            sourceRead.Close();
                        }
                    }
                    else // We are good, just copy the file
                    {
                        File.Copy(Path.Combine(Environment.GetEnvironmentVariable("HOMEPATH"), "history"), Path.Combine(installPath, @"config\history"), true);
                    }
                }
                if (File.Exists(Path.Combine(Environment.GetEnvironmentVariable("HOMEPATH"), "mcebuddy.conf")))
                {
                    File.Copy(Path.Combine(Environment.GetEnvironmentVariable("HOMEPATH"), "mcebuddy.conf"), Path.Combine(installPath, @"config\mcebuddy.conf.old"), true);
                }
                if (File.Exists(Path.Combine(Environment.GetEnvironmentVariable("HOMEPATH"), "profiles.conf")))
                {
                    File.Copy(Path.Combine(Environment.GetEnvironmentVariable("HOMEPATH"), "profiles.conf"), Path.Combine(installPath, @"config\profiles.conf.old"), true);
                }
                if (File.Exists(Path.Combine(Environment.GetEnvironmentVariable("HOMEPATH"), "comskip.ini")))
                {
                    File.Copy(Path.Combine(Environment.GetEnvironmentVariable("HOMEPATH"), "comskip.ini"), Path.Combine(installPath, @"comskip\comskip.ini.old"), true);
                }

                // Copy the settings from the last config file (retain user settings) (this will also take care of UTF16LE conversion for ini)
                if (File.Exists(Path.Combine(Environment.GetEnvironmentVariable("HOMEPATH"), "mcebuddy.conf")))
                {
                    MCEBuddyConf mceConf = new MCEBuddyConf(Path.Combine(Environment.GetEnvironmentVariable("HOMEPATH"), "mcebuddy.conf")); // Read the old config file
                    mceConf.WriteSettings(Path.Combine(installPath, @"config\mcebuddy.conf"));                                              // Write to the new installation file
                }
            }
            catch (Exception exp)
            {
                Log.WriteSystemEventLog("Failed to restore config files. Error:" + exp.ToString(), EventLogEntryType.Error);
            }

            try
            {
                // Install extras (such as filters etc)
                // Check if Haali Media Splitter is installed, else install it
                string haaliKey = "";

                if (Environment.Is64BitOperatingSystem)
                {
                    haaliKey = @"Software\Wow6432Node\HaaliMkx";
                }
                else
                {
                    haaliKey = @"Software\HaaliMkx";
                }

                if (Registry.LocalMachine.OpenSubKey(haaliKey) == null)
                {
                    if (MessageBox.Show("MCEBuddy suggests installing Haali Media Splitter for MKV playback support.\nPress OK to Install.", "MKV Playback Support Not Found", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.OK)
                    {
                        RunCustomApp(Path.Combine(installPath, "extras", "MatroskaSplitter"), "/S", true); // Install Haali Media Splitter (required for MKV playback)
                    }
                }

                // WTV Playback: Uninstall Windows Update KB2670838 if the resulting file does not play in MCE/WMP - nothing to do with ffdshow
                // Check if FFDSHOW is installed, else install FFDSHOW for MPEG2/AVI support else NoRecode profiles does not work
                bool   modifyReg  = true;
                string ffdshowKey = "";

                if (Environment.Is64BitOperatingSystem)
                {
                    ffdshowKey = @"Software\GNU\ffdshow64";
                }
                else
                {
                    ffdshowKey = @"Software\GNU\ffdshow";
                }

                if (Registry.LocalMachine.OpenSubKey(ffdshowKey) == null) // if the key doesn't exist i.e. not installed, it returns null
                {
                    if (MessageBox.Show("MCEBuddy suggests installing FFDShow for MPEG2/AVI playback support.\nPress OK to install.", "FFDShow Not Found", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.OK)
                    {
                        if (RunCustomAppWithMediumPrivilege(Path.Combine(installPath, "extras", "ffdshow.exe"), " /silent", true) == true) // FFDShow needs to be installed with Medium Privileges else the installation does not work
                        {
                            Registry.LocalMachine.DeleteSubKeyTree(@"Software\GNU");                                                       // Delete all the keys under GNU (we will only create those required later) - TODO: Can we find a clean way to do a custom install for FFDSHOw, default Silent install enables many filters not required
                        }
                        else
                        {
                            MessageBox.Show("FFDShow installation error, please install it manually from the Extra's folder in the MCEBuddy Installation directory.\nEnsure you select MPEG2 during installation", "Error installing FFDSHOW");
                            modifyReg = false;
                        }
                    }
                    else
                    {
                        modifyReg = false;
                    }
                }

                // FFDSHOW, enable the MPEG-2 splitter in the registry (whenever it's installed)
                if (modifyReg)
                {
                    Registry.LocalMachine.CreateSubKey(ffdshowKey); // Create the key if required (since the silent installation does not create one)
                    Registry.LocalMachine.OpenSubKey(ffdshowKey, true).SetValue("mpegAVI", 1, RegistryValueKind.DWord);
                    Registry.LocalMachine.OpenSubKey(ffdshowKey, true).SetValue("mpg2", 1, RegistryValueKind.DWord);
                    Registry.LocalMachine.OpenSubKey(ffdshowKey, true).SetValue("mpg1", 1, RegistryValueKind.DWord);
                }

                // Install ShowAnalyzer - last one, delayed start to avoid MSI install conflict (only 1 at a time)
                if (!Scanner.ShowAnalyzerInstalled()) // only if not installed
                {
                    if (MessageBox.Show("MCEBuddy comes with Comskip commercial detection software built in. However some countries have better commercial detection with ShowAnalyzer.\nPress OK if you would like to install ShowAnalyzer.", "Commercial detection options", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.OK)
                    {
                        RunCustomApp(Path.Combine(installPath, "extras", "InstallShowAnalyzerDelayed.bat"), "", false);
                    }
                }
            }
            catch (Exception exp)
            {
                Log.WriteSystemEventLog("Failed to install custom apps. Error:" + exp.ToString(), EventLogEntryType.Error);
            }

            try
            {
                //Set the restart properties for the service
                ServiceControlManager scm = new ServiceControlManager();
                scm.SetRestartOnFailure(engineName);
            }
            catch (Exception exp)
            {
                Log.WriteSystemEventLog("Failed to set MCEBuddy service restart parameters. Error:" + exp.ToString(), EventLogEntryType.Error);
            }

            /*string installPath = Context.Parameters["TARGETDIR"].Replace(@"\\", @"\").Trim();
             * CreateExposedDirectory(Path.Combine(installPath, "config"));
             * CreateExposedDirectory(Path.Combine(installPath, "log"));
             * CreateExposedDirectory(Path.Combine(installPath, "working"));*///Dont' create directories here since it create Canonical issues, create within application at runtime

            WindowsService.StartService(engineName);
        }
示例#24
0
        public static int DecodeHeader(System.IO.Stream buffer, out PacketTypes type, out Flags1 flags1, out Flags2 flags2, out Encodings encoding, out UInt16 serial_high_low, out Guid object_id, out Guid interface_id, out Guid activity_id, out UInt32 server_boot_time, out UInt32 sequence_no, out Operations op, out UInt16 body_length, out UInt16 fragment_no)
        {
            int    ret = 0;
            byte   tmp1;
            UInt16 tmp2;
            UInt32 tmp3;

            serial_high_low = 0;

            ret += DCP.DecodeU8(buffer, out tmp1);             //RPCVersion
            if (tmp1 != 4)
            {
                throw new Exception("Wrong protocol");
            }
            ret             += DCP.DecodeU8(buffer, out tmp1);
            type             = (PacketTypes)tmp1;
            ret             += DCP.DecodeU8(buffer, out tmp1);
            flags1           = (Flags1)tmp1;
            ret             += DCP.DecodeU8(buffer, out tmp1);
            flags2           = (Flags2)tmp1;
            ret             += DCP.DecodeU16(buffer, out tmp2);
            encoding         = (Encodings)tmp2;
            ret             += DCP.DecodeU8(buffer, out tmp1); //pad
            ret             += DCP.DecodeU8(buffer, out tmp1);
            serial_high_low |= (UInt16)(tmp1 << 8);
            ret             += DecodeGuid(buffer, encoding, out object_id);
            ret             += DecodeGuid(buffer, encoding, out interface_id);
            ret             += DecodeGuid(buffer, encoding, out activity_id);
            ret             += DecodeU32(buffer, encoding, out server_boot_time);
            ret             += DecodeU32(buffer, encoding, out tmp3);   //interface version
            if ((tmp3 & 0xFFFF) != 1)
            {
                throw new Exception("Wrong protocol version");
            }
            ret             += DecodeU32(buffer, encoding, out sequence_no);
            ret             += DecodeU16(buffer, encoding, out tmp2);
            op               = (Operations)tmp2;
            ret             += DecodeU16(buffer, encoding, out tmp2);     //interface hint
            ret             += DecodeU16(buffer, encoding, out tmp2);     //activity hint
            ret             += DecodeU16(buffer, encoding, out body_length);
            ret             += DecodeU16(buffer, encoding, out fragment_no);
            ret             += DCP.DecodeU8(buffer, out tmp1); //authentication protocol
            ret             += DCP.DecodeU8(buffer, out tmp1);
            serial_high_low |= tmp1;

            return(ret);
        }
        private void ProcessCsv()
        {
            string _filePath = FoldersHelper.GetPathAbsolut(FolderType.PriceTemp);
            string _fullPath = string.Format("{0}{1}", _filePath, "ostatki.csv");

            LogInvalidData("Start working on Update (1C). File " + _fullPath + DateTime.Now.ToString());


            if (!File.Exists(_fullPath))
            {
                return;
            }

            long count = 0;

            using (var csv = new CsvHelper.CsvReader(new StreamReader(_fullPath, Encodings.GetEncoding())))
            {
                csv.Configuration.Delimiter       = Separators.GetCharSeparator();
                csv.Configuration.HasHeaderRecord = true;
                while (csv.Read())
                {
                    count++;
                }
            }

            ImportStatistic.TotalRow = count;

            LogInvalidData("ImportStatistic.TotalRow = " + count.ToString() + DateTime.Now.ToString());

            using (var csv = new CsvHelper.CsvReader(new StreamReader(_fullPath, Encodings.GetEncoding())))
            {
                csv.Configuration.Delimiter       = Separators.GetCharSeparator();
                csv.Configuration.HasHeaderRecord = true;


                bool firstRead = true;
                while (csv.Read())
                {
                    try
                    {
                        if (firstRead)
                        {
                            for (int i = 0; i < csv.FieldHeaders.Length; i++)
                            {
                                FieldMapping.Add(csv.FieldHeaders[i], i);
                            }
                            firstRead = false;
                        }


                        var productInStrings = new Dictionary <ProductFields.Fields, string>();

                        string nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Sku);
                        if (FieldMapping.ContainsKey(nameField))
                        {
                            productInStrings.Add(ProductFields.Fields.Sku, Convert.ToString(csv[FieldMapping[nameField]]));
                        }

                        nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Name).Trim('*');
                        if (FieldMapping.ContainsKey(nameField))
                        {
                            var name = Convert.ToString(csv[FieldMapping[nameField]]);
                            if (!string.IsNullOrEmpty(name))
                            {
                                productInStrings.Add(ProductFields.Fields.Name, name);
                            }
                            else
                            {
                                LogInvalidData(string.Format(Resource.Admin_ImportCsv_CanNotEmpty, ProductFields.GetDisplayNameByEnum(ProductFields.Fields.Name), ImportStatistic.RowPosition + 2));
                                continue;
                            }
                        }

                        nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Enabled).Trim('*');
                        if (FieldMapping.ContainsKey(nameField))
                        {
                            string enabled = Convert.ToString(csv[FieldMapping[nameField]]);
                            productInStrings.Add(ProductFields.Fields.Enabled, enabled);
                            //product.Enabled = !string.IsNullOrEmpty(enabled) && enabled.Trim().Equals("+");
                        }

                        nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Discount);
                        if (FieldMapping.ContainsKey(nameField))
                        {
                            var discount = Convert.ToString(csv[FieldMapping[nameField]]);
                            if (string.IsNullOrEmpty(discount))
                            {
                                discount = "0";
                            }
                            decimal tmp;
                            if (decimal.TryParse(discount, out tmp))
                            {
                                productInStrings.Add(ProductFields.Fields.Discount, tmp.ToString());
                            }
                            else if (decimal.TryParse(discount, NumberStyles.Any, CultureInfo.InvariantCulture, out tmp))
                            {
                                productInStrings.Add(ProductFields.Fields.Discount, tmp.ToString());
                            }
                            else
                            {
                                LogInvalidData(string.Format(Resource.Admin_ImportCsv_MustBeNumber, ProductFields.GetDisplayNameByEnum(ProductFields.Fields.Discount), ImportStatistic.RowPosition + 2));
                                continue;
                            }
                        }

                        nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Weight);
                        if (FieldMapping.ContainsKey(nameField))
                        {
                            var weight = Convert.ToString(csv[FieldMapping[nameField]]);
                            if (string.IsNullOrEmpty(weight))
                            {
                                weight = "0";
                            }
                            decimal tmp;
                            if (decimal.TryParse(weight, out tmp))
                            {
                                productInStrings.Add(ProductFields.Fields.Weight, tmp.ToString());
                            }
                            else if (decimal.TryParse(weight, NumberStyles.Any, CultureInfo.InvariantCulture, out tmp))
                            {
                                productInStrings.Add(ProductFields.Fields.Weight, tmp.ToString());
                            }
                            else
                            {
                                LogInvalidData(string.Format(Resource.Admin_ImportCsv_MustBeNumber, ProductFields.GetDisplayNameByEnum(ProductFields.Fields.Weight), ImportStatistic.RowPosition + 2));
                                continue;
                            }
                        }

                        nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Size);
                        if (FieldMapping.ContainsKey(nameField))
                        {
                            productInStrings.Add(ProductFields.Fields.Size, Convert.ToString(csv[FieldMapping[nameField]]));
                        }

                        nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.BriefDescription);
                        if (FieldMapping.ContainsKey(nameField))
                        {
                            productInStrings.Add(ProductFields.Fields.BriefDescription, Convert.ToString(csv[FieldMapping[nameField]]));
                        }

                        nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Description);
                        if (FieldMapping.ContainsKey(nameField))
                        {
                            productInStrings.Add(ProductFields.Fields.Description, Convert.ToString(csv[FieldMapping[nameField]]));
                        }

                        nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Price).Trim('*');
                        if (FieldMapping.ContainsKey(nameField))
                        {
                            var price = Convert.ToString(csv[FieldMapping[nameField]]);
                            if (string.IsNullOrEmpty(price))
                            {
                                price = "0";
                            }
                            decimal tmp;
                            if (decimal.TryParse(price, out tmp))
                            {
                                productInStrings.Add(ProductFields.Fields.Price, tmp.ToString());
                            }
                            else if (decimal.TryParse(price, NumberStyles.Any, CultureInfo.InvariantCulture, out tmp))
                            {
                                productInStrings.Add(ProductFields.Fields.Price, tmp.ToString());
                            }
                            else
                            {
                                LogInvalidData(string.Format(Resource.Admin_ImportCsv_MustBeNumber, ProductFields.GetDisplayNameByEnum(ProductFields.Fields.Price), ImportStatistic.RowPosition + 2));
                                continue;
                            }
                        }

                        nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.PurchasePrice);
                        if (FieldMapping.ContainsKey(nameField))
                        {
                            var sypplyprice = Convert.ToString(csv[FieldMapping[nameField]]);
                            if (string.IsNullOrEmpty(sypplyprice))
                            {
                                sypplyprice = "0";
                            }
                            decimal tmp;
                            if (decimal.TryParse(sypplyprice, out tmp))
                            {
                                productInStrings.Add(ProductFields.Fields.PurchasePrice, tmp.ToString());
                            }
                            else if (decimal.TryParse(sypplyprice, NumberStyles.Any, CultureInfo.InvariantCulture, out tmp))
                            {
                                productInStrings.Add(ProductFields.Fields.PurchasePrice, tmp.ToString());
                            }
                            else
                            {
                                LogInvalidData(string.Format(Resource.Admin_ImportCsv_MustBeNumber, ProductFields.GetDisplayNameByEnum(ProductFields.Fields.PurchasePrice), ImportStatistic.RowPosition + 2));
                                continue;
                            }
                        }

                        nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.ShippingPrice);
                        if (FieldMapping.ContainsKey(nameField))
                        {
                            var shippingPrice = Convert.ToString(csv[FieldMapping[nameField]]);
                            if (string.IsNullOrEmpty(shippingPrice))
                            {
                                shippingPrice = "0";
                            }
                            decimal tmp;
                            if (decimal.TryParse(shippingPrice, out tmp))
                            {
                                productInStrings.Add(ProductFields.Fields.ShippingPrice, tmp.ToString());
                            }
                            else if (decimal.TryParse(shippingPrice, NumberStyles.Any, CultureInfo.InvariantCulture, out tmp))
                            {
                                productInStrings.Add(ProductFields.Fields.ShippingPrice, tmp.ToString());
                            }
                            else
                            {
                                LogInvalidData(string.Format(Resource.Admin_ImportCsv_MustBeNumber, ProductFields.GetDisplayNameByEnum(ProductFields.Fields.ShippingPrice), ImportStatistic.RowPosition + 2));
                                continue;
                            }
                        }

                        nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Amount);
                        if (FieldMapping.ContainsKey(nameField))
                        {
                            var amount = Convert.ToString(csv[FieldMapping[nameField]]);
                            if (string.IsNullOrEmpty(amount))
                            {
                                amount = "0";
                            }
                            int tmp;
                            if (int.TryParse(amount, out tmp))
                            {
                                productInStrings.Add(ProductFields.Fields.Amount, amount);
                            }
                            else
                            {
                                LogInvalidData(string.Format(Resource.Admin_ImportCsv_MustBeNumber, ProductFields.GetDisplayNameByEnum(ProductFields.Fields.Amount), ImportStatistic.RowPosition + 2));
                                continue;
                            }
                        }

                        nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Unit);
                        if (FieldMapping.ContainsKey(nameField))
                        {
                            productInStrings.Add(ProductFields.Fields.Unit, Convert.ToString(csv[FieldMapping[nameField]]));
                        }

                        nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.ParamSynonym);
                        if (FieldMapping.ContainsKey(nameField))
                        {
                            string rewurl = Convert.ToString(csv[FieldMapping[nameField]]);
                            productInStrings.Add(ProductFields.Fields.ParamSynonym, rewurl);
                        }

                        nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Title);
                        if (FieldMapping.ContainsKey(nameField))
                        {
                            productInStrings.Add(ProductFields.Fields.Title, Convert.ToString(csv[FieldMapping[nameField]]));
                        }

                        nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.MetaKeywords);
                        if (FieldMapping.ContainsKey(nameField))
                        {
                            productInStrings.Add(ProductFields.Fields.MetaKeywords, Convert.ToString(csv[FieldMapping[nameField]]));
                        }

                        nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.MetaDescription);
                        if (FieldMapping.ContainsKey(nameField))
                        {
                            productInStrings.Add(ProductFields.Fields.MetaDescription, Convert.ToString(csv[FieldMapping[nameField]]));
                        }

                        nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Photos);
                        if (FieldMapping.ContainsKey(nameField))
                        {
                            productInStrings.Add(ProductFields.Fields.Photos, Convert.ToString(csv[FieldMapping[nameField]]));
                        }

                        nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Markers);
                        if (FieldMapping.ContainsKey(nameField))
                        {
                            productInStrings.Add(ProductFields.Fields.Markers, Convert.ToString(csv[FieldMapping[nameField]]));
                        }

                        nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Properties);
                        if (FieldMapping.ContainsKey(nameField))
                        {
                            productInStrings.Add(ProductFields.Fields.Properties, Convert.ToString(csv[FieldMapping[nameField]]));
                        }

                        nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Producer);
                        if (FieldMapping.ContainsKey(nameField))
                        {
                            productInStrings.Add(ProductFields.Fields.Producer, Convert.ToString(csv[FieldMapping[nameField]]));
                        }

                        nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.OrderByRequest);
                        if (FieldMapping.ContainsKey(nameField))
                        {
                            string orderbyrequest = Convert.ToString(csv[FieldMapping[nameField]]);
                            productInStrings.Add(ProductFields.Fields.OrderByRequest, orderbyrequest);
                        }

                        nameField = ProductFields.GetStringNameByEnum(ProductFields.Fields.Category).Trim('*');
                        if (FieldMapping.ContainsKey(nameField))
                        {
                            var parentCategory = Convert.ToString(csv[FieldMapping[nameField]]);
                            if (!string.IsNullOrEmpty(parentCategory))
                            {
                                productInStrings.Add(ProductFields.Fields.Category, parentCategory);
                            }
                        }



                        ImportProduct.UpdateInsertProduct(productInStrings, false);
                    }
                    catch (Exception ex)
                    {
                        LogInvalidData("Ex  " + ex.Message + DateTime.Now.ToString());
                    }
                }


                //All amounts to zero. except that was updated 0.02 = 30 minutes before and SubBrandID != -2 (tools.by)
                string script = "UPDATE Catalog.Offer SET Amount = 0 FROM Catalog.Product INNER JOIN Catalog.Offer ON Catalog.Product.ProductId = Catalog.Offer.ProductID WHERE (Catalog.Product.DateModified < GETDATE() - 0.02) AND Amount < 9000 ";
                ExecuteScript(script);

                LogInvalidData("Amounts of products that was not updated to zero" + DateTime.Now.ToString());

                LogInvalidData(" CategoryService.RecalculateProductsCountManual() before " + DateTime.Now.ToString());
                CategoryService.RecalculateProductsCountManual();
                LogInvalidData(" CategoryService.RecalculateProductsCountManual() after " + DateTime.Now.ToString());
            }

            try
            {
                LogInvalidData("  LuceneSearch.CreateAllIndexInBackground(); " + DateTime.Now.ToString());
                LuceneSearch.CreateAllIndexInBackground();
                CacheManager.Clean();
                LogInvalidData("   File.Cop file:" + _fullPath + DateTime.Now.ToString());
                //  File.Copy(_fullPath, _fullPath.Replace("ostatki.csv", "ostatki_done_" + DateTime.Now.ToString("M-d-yyyy-HH-mm") + ".csv"));

                FileHelpers.DeleteFile(_fullPath.Replace("ostatki.csv", "Instrument_opt_by__ostatki.csv"));
                File.Copy(_fullPath, _fullPath.Replace("ostatki.csv", "Instrument_opt_by__ostatki.csv"));
                FileHelpers.DeleteFile(_fullPath);
                //UPdate Sorting
                LogInvalidData("   //UPdate Sorting " + DateTime.Now.ToString());
                AdvantShop.Core.SQLDataAccess.ExecuteNonQuery("[Catalog].[sp_UpdateSortingInCategories]", CommandType.StoredProcedure);
                LogInvalidData("   All Done:  " + DateTime.Now.ToString());
            }
            catch (Exception ex)
            {
                LogInvalidData("Ex 2 " + ex.Message + DateTime.Now.ToString());
            }
        }
示例#26
0
        public static void SaveProductsToCsv(string path, Encodings.EncodingsEnum encodeType, Separators.SeparatorsEnum delimetr, List <ProductFields.Fields> fieldMapping)
        {
            using (var writer = new CsvHelper.CsvWriter(new StreamWriter(path, false, Encodings.GetEncoding(encodeType))))
            {
                writer.Configuration.Delimiter = Separators.GetCharSeparator(delimetr);
                //var fields = new List<string> { "SKU", "Name*", "ParamSynonym", "Category", "Enabled*", "Price*", "PurchasePrice*", "Amount*", "Unit", "Discount", "ShippingPrice", "Weight", "Size", "BriefDescription", "Description" };
                //foreach (var item in fields)
                //    writer.WriteField(item);
                foreach (var item in fieldMapping)
                {
                    writer.WriteField(ProductFields.GetStringNameByEnum(item));
                }
                writer.NextRecord();
                var items = ProductService.GetProducts();
                if (items == null)
                {
                    return;
                }
                var regex = new Regex("^[0-9]+$");
                for (int j = 0; j < items.Count; j++)
                {
                    var product = items[j];
                    if (!ExportStatistic.IsRun)
                    {
                        return;
                    }
                    var offer = product.Offers.FirstOrDefault() ?? new Offer {
                        Amount = 0, Price = 0, SupplyPrice = 0, Unit = "", ShippingPrice = 0
                    };
                    var meta = MetaInfoService.GetMetaInfo(product.ID, MetaType.Product) ??
                               new MetaInfo(0, 0, MetaType.Product, string.Empty, string.Empty, string.Empty);
                    for (int i = 0; i < fieldMapping.Count; i++)
                    {
                        var item = fieldMapping[i];
                        //Changed by Evgeni to insert dotes
                        if (item == ProductFields.Fields.Sku)
                        {
                            string art = product.ArtNo;
                            //if (art.Contains("-") == false && art.Length > 7)
                            // {
                            //     art = art.Insert(7, ".").Insert(4, ".").Insert(1, ".");
                            // }
                            //
                            writer.WriteField(art);
                            // writer.WriteField(product.ArtNo);
                        }
                        //
                        if (item == ProductFields.Fields.Name)
                        {
                            writer.WriteField(product.Name);
                        }
                        if (item == ProductFields.Fields.ParamSynonym)
                        {
                            if (regex.IsMatch(product.UrlPath))
                            {
                                writer.WriteField("IPD" + product.UrlPath);
                            }
                            else
                            {
                                writer.WriteField(product.UrlPath);
                            }
                        }
                        if (item == ProductFields.Fields.Category)
                        {
                            writer.WriteField((GetCategoryStringByProductID(product.ProductId)));
                        }
                        if (item == ProductFields.Fields.Enabled)
                        {
                            writer.WriteField(product.Enabled ? "+" : "-");
                        }
                        if (item == ProductFields.Fields.Price)
                        {
                            writer.WriteField(offer.Price.ToString("F2"));
                        }
                        if (item == ProductFields.Fields.PurchasePrice)
                        {
                            writer.WriteField(offer.SupplyPrice.ToString("F2"));
                        }
                        if (item == ProductFields.Fields.Amount)
                        {
                            writer.WriteField(offer.Amount.ToString());
                        }
                        if (item == ProductFields.Fields.Unit)
                        {
                            writer.WriteField(offer.Unit);
                        }
                        if (item == ProductFields.Fields.ShippingPrice)
                        {
                            writer.WriteField(offer.ShippingPrice.ToString("F2"));
                        }
                        if (item == ProductFields.Fields.Discount)
                        {
                            writer.WriteField(product.Discount.ToString("F2"));
                        }
                        if (item == ProductFields.Fields.Weight)
                        {
                            writer.WriteField(product.Weight.ToString("F2"));
                        }
                        if (item == ProductFields.Fields.Size)
                        {
                            writer.WriteField(product.Size.Replace("|", " x "));
                        }
                        if (item == ProductFields.Fields.BriefDescription)
                        {
                            writer.WriteField(product.BriefDescription);
                        }
                        if (item == ProductFields.Fields.Description)
                        {
                            writer.WriteField(product.Description);
                        }

                        if (item == ProductFields.Fields.Title)
                        {
                            writer.WriteField(meta.Title);
                        }
                        if (item == ProductFields.Fields.MetaKeywords)
                        {
                            writer.WriteField(meta.MetaKeywords);
                        }
                        if (item == ProductFields.Fields.MetaDescription)
                        {
                            writer.WriteField(meta.MetaDescription);
                        }
                        if (item == ProductFields.Fields.Markers)
                        {
                            writer.WriteField(MarkersToString(product));
                        }
                        if (item == ProductFields.Fields.Photos)
                        {
                            writer.WriteField(PhotoToString(product.ProductPhotos));
                        }
                        if (item == ProductFields.Fields.Properties)
                        {
                            writer.WriteField(PropertiesToString(product.ProductPropertyValues));
                        }
                        //Changed by Evgeni
                        if (item == ProductFields.Fields.EAN)
                        {
                            writer.WriteField(product.EAN);
                        }
                        if (item == ProductFields.Fields.SubBrandId)
                        {
                            writer.WriteField(product.SubBrandId);
                        }

                        //
                        if (item == ProductFields.Fields.Producer)
                        {
                            var brand = BrandService.GetBrandById(product.BrandId);
                            writer.WriteField(brand != null ? brand.Name : string.Empty);
                        }
                        if (item == ProductFields.Fields.OrderByRequest)
                        {
                            writer.WriteField(product.OrderByRequest ? "+" : "-");
                        }
                    }
                    writer.NextRecord();
                    ExportStatistic.RowPosition++;
                }
            }
        }
示例#27
0
 /// <summary>
 /// Gets the value.
 /// </summary>
 /// <param name="encoding">The encoding.</param>
 /// <returns>The value in byte (last 7 bit).</returns>
 /// <exception cref="InvalidOperationException">encoding is not valid.</exception>
 public byte Get(Encodings encoding)
 => encoding switch
 {
示例#28
0
 /// <summary>
 /// Sets the encoding in which the file will be saved upon dumping it to the disc.
 /// </summary>
 /// <param name="type">The given type of output encoding.</param>
 public void SetOutputEncoding(EncodingType type)
 {
     OutputEncoding = Encodings.GetEncoding(type);
 }
示例#29
0
        /// <summary>
        /// Converts a string from a encoding to another encoding
        /// </summary>
        /// <param name="source">The string to convert</param>
        /// <param name="from">The source strings encoding</param>
        /// <param name="to">The target encoding</param>
        /// <returns>The converted string</returns>
        public static string Convert(this string source, Encodings from, Encodings to)
        {
            var toEncoding = ToEncoding(to);

            return(toEncoding.GetString(source.ConvertToBytes(from, to)));
        }
示例#30
0
 UInt32 MetadataTokenSize(Encodings Which)
 {
     EncodingDesc E = EncodingDescs[(int) Which];
     int TagBits = E.TagBits;
     UInt32 MaxRows = 0;
     foreach (Tables Table in E.WhichTables)
     {
         if (Table == Tables.Invalid) continue;
         UInt32 N = NRows[(int)Table];
         if (N > MaxRows) MaxRows = N;
     }
     return (MaxRows < (1 << (16 - TagBits))) ? 2U : 4U;
 }
示例#31
0
 static ShxFile()
 {
     try
     {
         ShxFile.AddBigfontEncoding("@EXTFONT2", Encodings.Dos932);
         ShxFile.AddBigfontEncoding("EXTFONT2", Encodings.Dos932);
         ShxFile.AddBigfontEncoding("BIGFONT", Encodings.Dos932);
         ShxFile.AddBigfontEncoding("EXTFONT", Encodings.Dos932);
     }
     catch (Exception ex)
     {
         Console.WriteLine((object)ex);
     }
     try
     {
         ShxFile.AddBigfontEncoding("CHINESET", Encodings.Ansi950);
     }
     catch (Exception ex)
     {
         Console.WriteLine((object)ex);
     }
     try
     {
         ShxFile.AddBigfontEncoding("GBCBIG", Encodings.Gb2312);
         ShxFile.AddBigfontEncoding("HZTXT", Encodings.Gb2312);
     }
     catch (Exception ex)
     {
         Console.WriteLine((object)ex);
     }
     try
     {
         ShxFile.AddBigfontEncoding("WHGDTXT", Encodings.Ksc5601);
         ShxFile.AddBigfontEncoding("WHGTXT", Encodings.Ksc5601);
         ShxFile.AddBigfontEncoding("WHTGTXT", Encodings.Ksc5601);
         ShxFile.AddBigfontEncoding("WHTMTXT", Encodings.Ksc5601);
     }
     catch (Exception ex)
     {
         Console.WriteLine((object)ex);
     }
     try
     {
         Encoding encoding = Encodings.GetEncoding(437);
         ShxFile.AddOldShxEncoding("COMPLEX", encoding);
         ShxFile.AddOldShxEncoding("COMPLEX8", encoding);
         ShxFile.AddOldShxEncoding("GOTHICE", encoding);
         ShxFile.AddOldShxEncoding("GOTHICG", encoding);
         ShxFile.AddOldShxEncoding("GOTHICI", encoding);
         ShxFile.AddOldShxEncoding("GREEKC", encoding);
         ShxFile.AddOldShxEncoding("GREEKS", encoding);
         ShxFile.AddOldShxEncoding("ISOCP", encoding);
         ShxFile.AddOldShxEncoding("ISOCP2", encoding);
         ShxFile.AddOldShxEncoding("ISOCP3", encoding);
         ShxFile.AddOldShxEncoding("ISOCT", encoding);
         ShxFile.AddOldShxEncoding("ISOCT2", encoding);
         ShxFile.AddOldShxEncoding("ISOCT3", encoding);
         ShxFile.AddOldShxEncoding("ITALIC", encoding);
         ShxFile.AddOldShxEncoding("ITALICC", encoding);
         ShxFile.AddOldShxEncoding("ITALICT", encoding);
         ShxFile.AddOldShxEncoding("MONOTXT", encoding);
         ShxFile.AddOldShxEncoding("ROMANC", encoding);
         ShxFile.AddOldShxEncoding("ROMAND", encoding);
         ShxFile.AddOldShxEncoding("ROMANS", encoding);
         ShxFile.AddOldShxEncoding("ROMANT", encoding);
         ShxFile.AddOldShxEncoding("SCRIPTC", encoding);
         ShxFile.AddOldShxEncoding("SCRIPTS", encoding);
         ShxFile.AddOldShxEncoding("SIMPLEX", encoding);
         ShxFile.AddOldShxEncoding("SIMPLEX8", encoding);
         ShxFile.AddOldShxEncoding("SYASTRO", encoding);
         ShxFile.AddOldShxEncoding("SYMAP", encoding);
         ShxFile.AddOldShxEncoding("SYMATH", encoding);
         ShxFile.AddOldShxEncoding("SYMETEO", encoding);
         ShxFile.AddOldShxEncoding("SYMUSIC", encoding);
         ShxFile.AddOldShxEncoding("TXT", encoding);
         ShxFile.AddOldShxEncoding("TXT8", encoding);
         ShxFile.AddOldShxEncoding("ATIR", Encodings.GetEncoding(862));
         ShxFile.AddFontCharRemapper("ATIR", new CharRemapDelegate(new FontCharRemapper(Encodings.GetEncoding(862), Encodings.GetEncoding(1255)).Remap));
         ShxFile.AddOldShxEncoding("HEBTXT", Encodings.GetEncoding(862));
         ShxFile.AddFontCharRemapper("HEBTXT", new CharRemapDelegate(new FontCharRemapper(Encodings.GetEncoding(862), Encodings.GetEncoding(1255)).Remap));
     }
     catch (Exception ex)
     {
         Console.WriteLine((object)ex);
     }
     try
     {
         ShxFile.AddOldShxEncoding("P131", Encodings.Ansi1251);
     }
     catch (Exception ex)
     {
         Console.WriteLine((object)ex);
     }
 }
示例#32
0
        //Added by Evgeni
        public static void SaveProductsToCsvAutospace(string path, Encodings.EncodingsEnum encodeType, Separators.SeparatorsEnum delimetr)
        {
            ImportStatistic.WriteLog("Start working on SaveProductsToCsvAutospace. DateTime: " + DateTime.Now);

            using (var writer = new CsvHelper.CsvWriter(new StreamWriter(path, false, Encodings.GetEncoding(encodeType))))
            {
                ImportStatistic.WriteLog("Start working on SaveProductsToCsvAutospace 2.Encoding: " + Encodings.GetEncoding(encodeType) + " DateTime: " + DateTime.Now);

                writer.Configuration.Delimiter = Separators.GetCharSeparator(delimetr);

                //var items = new List<Product>();

                //using (var db = new SQLDataAccess())
                //{
                //    db.cnOpen();
                //    items = (List<Product>)ProductService.GetProductsWhere(db, "ArtNo like '2.607.001.733'");
                //    db.cnClose();
                //}
                var items = ProductService.GetProducts();// .Where(t => t.ArtNo.Contains("2.607.001.733")).ToList();

                List <string> loadedProducts = new List <string>();

                ImportStatistic.WriteLog("Start working on SaveProductsToCsvAutospace 3. DateTime: " + DateTime.Now + "Number of products to proceed: " + items.Count);
                //select only relevants offers
                //  items = items.Where(t => t.Brand.Name.ToLower() == "bosch" || t.Brand.Name.ToLower() == "skil").Where(t => t.Offers.FirstOrDefault().Amount > 0 && t.Offers.FirstOrDefault().Price > 0).ToList();

                if (items == null)
                {
                    return;
                }
                var    regex = new Regex("^[0-9]+$");
                string pcs   = "шт.";
                for (int j = 0; j < items.Count; j++)
                {
                    try
                    {
                        if (j % 1000 == 0)
                        {
                            ImportStatistic.WriteLog("Start working on SaveProductsToCsvAutospace 4. DateTime: " + DateTime.Now
                                                     + " File No " + j);
                        }

                        //check that product was not inserted yet
                        if (loadedProducts.Where(t => t.Contains(items[j].ArtNo)).ToList().Count > 0)
                        {
                            continue;
                        }
                        else
                        {
                            loadedProducts.Add(items[j].ArtNo);
                        }

                        var product = items[j];
                        var offer   = product.Offers.Where(t => t.OfferListId == 15).FirstOrDefault() ?? new Offer {
                            Amount = 0, Price = 0, SupplyPrice = 0, Unit = "", ShippingPrice = 0
                        };                                                                                                                                                                //get only spec price
                        if (offer.OfferListId != 15 || offer.Amount <= 0 || offer.Price <= 0)
                        {
                            continue;
                        }

                        if (product.Brand == null)
                        {
                            if (product.ArtNo.ToLower().StartsWith("f"))
                            {
                                writer.WriteField("Skil");
                            }
                            else
                            {
                                writer.WriteField("Bosch");
                            }
                        }
                        else
                        {
                            writer.WriteField(product.Brand.Name);
                        }

                        writer.WriteField(product.ArtNo);
                        writer.WriteField(product.BriefDescription.Replace(";", "").Replace("&nbsp;", " ").Replace(",", "").Replace("<p>", "").Replace("<p/>", ""));

                        if (product.ProductCategories.Count == 0)
                        {
                            writer.WriteField("Прочее");
                        }
                        else
                        {
                            writer.WriteField(product.ProductCategories.FirstOrDefault().Name.Replace(";", "").Replace("&nbsp;", "").Replace(",", ""));
                        }

                        writer.WriteField(offer.Amount);
                        writer.WriteField(offer.Price.ToString("F2"));
                        writer.WriteField(pcs);
                        writer.WriteField("1");

                        writer.NextRecord();
                    }
                    catch (Exception ex)
                    {
                        ImportStatistic.WriteLog("Error while adding product:" + ex.Message);
                    }
                }

                ImportStatistic.WriteLog("End working on SaveProductsToCsvAutospace 5. DateTime: " + DateTime.Now);
            }
            ImportStatistic.WriteLog("End working on SaveProductsToCsvAutospace 6. DateTime: " + DateTime.Now);
        }
        public void SetEncoding(KeyType keyType, Encodings encodingType)
        {
            Encoding encoding = null;

            switch (encodingType)
            {
                    //case Encodings.None:
                case Encodings.ASCII :
                    encoding = Encoding.ASCII;
                    break;
                case Encodings.Unicode :
                    encoding = Encoding.Unicode;
                    break;
                case Encodings.UTF32 :
                    encoding = Encoding.UTF32;
                    break;
                case Encodings.UTF7 :
                    encoding = Encoding.UTF7;
                    break;
                case Encodings.UTF8 :
                    encoding = Encoding.UTF8;
                    break;
            }

            var engine = new DPAPIEngine(keyType)
                .SetEncoding(encoding);

            byte[] plainText = encoding.GetBytes(GenerateClearText());

            byte[] encrypted = engine.Encrypt(plainText);

            byte[] decrypted = engine.Decrypt(encrypted);

            Assert.AreNotEqual(plainText, encrypted);
            Assert.AreNotEqual(encrypted, decrypted);
            Assert.AreEqual(plainText, decrypted);
        }
示例#34
0
 public FileGenerator()
 {
     name     = string.Empty;
     FilePath = string.Empty;
     Encoding = Encodings.None;
 }
示例#35
0
        /*
        internal UInt32 ReadEncodedInt()
        {
            byte first = B.ReadByte();
            if ((first & 0x80) == 0)
                return first;
            byte second = B.ReadByte();
            if ((first & 0xC0) == 0x80)
                return ((uint)(first & 0x7F)) << 8 | second;
            else if ((first & 0xE0) == 0xC0)
            {
                byte third = B.ReadByte();
                byte fourth = B.ReadByte();
                return ((uint)(first & 0x1F) << 24) | ((uint)second) << 16 | ((uint)third) << 8 | (uint)fourth;
            }
            else
                throw new BadImageFormatException(Res.InvalidCompressedInt);
        }
        */

        internal MetadataToken ReadMetadataToken(Encodings E)
        {
            UInt32 Code = (MetadataTokenSize(E) == 2) ? B.ReadUInt16() : B.ReadUInt32();
            MetadataToken Result;
            EncodingDesc Desc = EncodingDescs[(Int32)E];
            Tables[] Ts = Desc.WhichTables;
            UInt32 Mask = (1U << Desc.TagBits) - 1;
            Result.Table = Ts[Code & Mask];
            Result.Index = Code >> Desc.TagBits;
            if (Result.Table == Tables.Invalid)
                throw new BadImageFormatException(Res.InvalidMetadataTokenNilTable);
            return Result;
        }
示例#36
0
 public MainViewModel()
 {
     Language = Languages.First();
     Encoding = Encodings.First();
 }
示例#37
0
 public ResponseHeader(ResponseHeader responseHeader) : base(responseHeader ?? new ResponseHeader())
 {
     responseHeader = responseHeader ?? new ResponseHeader(); ResponseCode = responseHeader.ResponseCode; ContentType = responseHeader.ContentType; Encoding = responseHeader.Encoding;
 }
示例#38
0
文件: Class1033.cs 项目: 15831944/WW
 public Class1033(Stream stream, DxfModel model)
 {
     this.stream_0       = stream;
     this.dxfModel_0     = model;
     this.memoryStream_0 = new MemoryStream(500);
     this.interface29_0  = Class724.Create(model.Header.AcadVersion, (Stream)this.memoryStream_0, Encodings.GetEncoding((int)model.Header.DrawingCodePage));
 }