public IActionResult Load(long?ID, long?ServiceType, long?langId)
        {
            GetAttributes operation = new GetAttributes();

            operation.ID   = ID;
            operation.Type = ServiceType;
            if (langId.HasValue)
            {
                operation.LangID = langId;
            }
            else
            {
                operation.LangID = 1;
            }

            var result = operation.QueryAsync().Result;

            if (result is ValidationsOutput)
            {
                return(Ok(new ApiResult <List <ValidationItem> >()
                {
                    Data = ((ValidationsOutput)result).Errors
                }));
            }
            else
            {
                return(Ok((List <Acttribute>)result));
            }
        }
 internal bool ExecuteImpl(Microsoft.Build.Shared.FileExists fileExists, Microsoft.Build.Shared.FileCreate fileCreate, GetAttributes fileGetAttributes, SetAttributes fileSetAttributes, SetLastAccessTime fileSetLastAccessTime, SetLastWriteTime fileSetLastWriteTime)
 {
     DateTime touchDateTime;
     try
     {
         touchDateTime = this.GetTouchDateTime();
     }
     catch (FormatException exception)
     {
         base.Log.LogErrorWithCodeFromResources("Touch.TimeSyntaxIncorrect", new object[] { exception.Message });
         return false;
     }
     bool flag = true;
     ArrayList list = new ArrayList();
     HashSet<string> set = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
     foreach (ITaskItem item in this.Files)
     {
         if (!set.Contains(item.ItemSpec))
         {
             if (this.TouchFile(item.ItemSpec, touchDateTime, fileExists, fileCreate, fileGetAttributes, fileSetAttributes, fileSetLastAccessTime, fileSetLastWriteTime))
             {
                 list.Add(item);
             }
             else
             {
                 flag = false;
             }
             set.Add(item.ItemSpec);
         }
     }
     this.TouchedFiles = (ITaskItem[]) list.ToArray(typeof(ITaskItem));
     return flag;
 }
Esempio n. 3
0
        /// <summary>
        /// Implementation of the execute method.
        /// </summary>
        /// <returns></returns>
        internal bool ExecuteImpl
        (
            FileExists fileExists,
            FileCreate fileCreate,
            GetAttributes fileGetAttributes,
            SetAttributes fileSetAttributes,
            SetLastAccessTime fileSetLastAccessTime,
            SetLastWriteTime fileSetLastWriteTime
        )
        {
            // See what time we are touching all files to
            DateTime touchDateTime;

            try
            {
                touchDateTime = GetTouchDateTime();
            }
            catch (FormatException e)
            {
                Log.LogErrorWithCodeFromResources("Touch.TimeSyntaxIncorrect", e.Message);
                return(false);
            }

            // Go through all files and touch 'em
            bool retVal          = true;
            var  touchedItems    = new ArrayList();
            var  touchedFilesSet = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            foreach (ITaskItem file in Files)
            {
                string path = FileUtilities.FixFilePath(file.ItemSpec);
                // For speed, eliminate duplicates caused by poor targets authoring
                if (touchedFilesSet.Contains(path))
                {
                    continue;
                }

                // Touch the file.  If the file was touched successfully then add it to our array of
                // touched items.
                if
                (
                    TouchFile
                    (
                        path,
                        touchDateTime,
                        fileExists,
                        fileCreate,
                        fileGetAttributes,
                        fileSetAttributes,
                        fileSetLastAccessTime,
                        fileSetLastWriteTime
                    )
                )
                {
                    touchedItems.Add(file);
                }
                else
                {
                    retVal = false;
                }

                // Add even on failure to avoid reattempting
                touchedFilesSet.Add(path);
            }

            // Now, set the property that indicates which items we touched.  Note that we
            // touch all the items
            TouchedFiles = (ITaskItem[])touchedItems.ToArray(typeof(ITaskItem));
            return(retVal);
        }
Esempio n. 4
0
        /// <summary>
        /// Helper method touches a file.
        /// </summary>
        /// <returns>"True" if the file was touched.</returns>
        private bool TouchFile
        (
            string file,
            DateTime dt,
            FileExists fileExists,
            FileCreate fileCreate,
            GetAttributes fileGetAttributes,
            SetAttributes fileSetAttributes,
            SetLastAccessTime fileSetLastAccessTime,
            SetLastWriteTime fileSetLastWriteTime
        )
        {
            if (!fileExists(file))
            {
                // If the file does not exist then we check if we need to create it.
                if (AlwaysCreate)
                {
                    Log.LogMessageFromResources(MessageImportance.Normal, "Touch.CreatingFile", file, "AlwaysCreate");
                    if (!CreateFile(file, fileCreate))
                    {
                        return(false);
                    }
                }
                else
                {
                    Log.LogErrorWithCodeFromResources("Touch.FileDoesNotExist", file);
                    return(false);
                }
            }
            else
            {
                Log.LogMessageFromResources(MessageImportance.Normal, "Touch.Touching", file);
            }

            // If the file is read only then we must either issue an error, or, if the user so
            // specified, make the file temporarily not read only.
            bool           needToRestoreAttributes = false;
            FileAttributes faOriginal = fileGetAttributes(file);

            if ((faOriginal & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
            {
                if (ForceTouch)
                {
                    try
                    {
                        FileAttributes faNew = (faOriginal & ~FileAttributes.ReadOnly);
                        fileSetAttributes(file, faNew);
                        needToRestoreAttributes = true;
                    }
                    catch (Exception e) when(ExceptionHandling.IsIoRelatedException(e))
                    {
                        Log.LogErrorWithCodeFromResources("Touch.CannotMakeFileWritable", file, e.Message);
                        return(false);
                    }
                }
            }

            // Do the actual touch operation
            bool retVal = true;

            try
            {
                fileSetLastAccessTime(file, dt);
                fileSetLastWriteTime(file, dt);
            }
            catch (Exception e) when(ExceptionHandling.IsIoRelatedException(e))
            {
                Log.LogErrorWithCodeFromResources("Touch.CannotTouch", file, e.Message);
                return(false);
            }
            finally
            {
                if (needToRestoreAttributes)
                {
                    // Attempt to restore the attributes.  If we fail here, then there is
                    // not much we can do.
                    try
                    {
                        fileSetAttributes(file, faOriginal);
                    }
                    catch (Exception e) when(ExceptionHandling.IsIoRelatedException(e))
                    {
                        Log.LogErrorWithCodeFromResources("Touch.CannotRestoreAttributes", file, e.Message);
                        retVal = false;
                    }
                }
            }

            return(retVal);
        }
Esempio n. 5
0
        private bool TouchFile(string file, DateTime dt, Microsoft.Build.Shared.FileExists fileExists, Microsoft.Build.Shared.FileCreate fileCreate, GetAttributes fileGetAttributes, SetAttributes fileSetAttributes, SetLastAccessTime fileSetLastAccessTime, SetLastWriteTime fileSetLastWriteTime)
        {
            if (!fileExists(file))
            {
                if (!this.AlwaysCreate)
                {
                    base.Log.LogErrorWithCodeFromResources("Touch.FileDoesNotExist", new object[] { file });
                    return(false);
                }
                base.Log.LogMessageFromResources(MessageImportance.Normal, "Touch.CreatingFile", new object[] { file, "AlwaysCreate" });
                if (!this.CreateFile(file, fileCreate))
                {
                    return(false);
                }
            }
            else
            {
                base.Log.LogMessageFromResources(MessageImportance.Normal, "Touch.Touching", new object[] { file });
            }
            bool           flag       = false;
            FileAttributes attributes = fileGetAttributes(file);

            if (((attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly) && this.ForceTouch)
            {
                try
                {
                    FileAttributes attributes2 = attributes & ~FileAttributes.ReadOnly;
                    fileSetAttributes(file, attributes2);
                    flag = true;
                }
                catch (Exception exception)
                {
                    if (Microsoft.Build.Shared.ExceptionHandling.NotExpectedException(exception))
                    {
                        throw;
                    }
                    base.Log.LogErrorWithCodeFromResources("Touch.CannotMakeFileWritable", new object[] { file, exception.Message });
                    return(false);
                }
            }
            bool flag2 = true;

            try
            {
                fileSetLastAccessTime(file, dt);
                fileSetLastWriteTime(file, dt);
            }
            catch (Exception exception2)
            {
                if (Microsoft.Build.Shared.ExceptionHandling.NotExpectedException(exception2))
                {
                    throw;
                }
                base.Log.LogErrorWithCodeFromResources("Touch.CannotTouch", new object[] { file, exception2.Message });
                return(false);
            }
            finally
            {
                if (flag)
                {
                    try
                    {
                        fileSetAttributes(file, attributes);
                    }
                    catch (Exception exception3)
                    {
                        if (Microsoft.Build.Shared.ExceptionHandling.NotExpectedException(exception3))
                        {
                            throw;
                        }
                        base.Log.LogErrorWithCodeFromResources("Touch.CannotRestoreAttributes", new object[] { file, exception3.Message });
                        flag2 = false;
                    }
                }
            }
            return(flag2);
        }
Esempio n. 6
0
        internal bool ExecuteImpl(Microsoft.Build.Shared.FileExists fileExists, Microsoft.Build.Shared.FileCreate fileCreate, GetAttributes fileGetAttributes, SetAttributes fileSetAttributes, SetLastAccessTime fileSetLastAccessTime, SetLastWriteTime fileSetLastWriteTime)
        {
            DateTime touchDateTime;

            try
            {
                touchDateTime = this.GetTouchDateTime();
            }
            catch (FormatException exception)
            {
                base.Log.LogErrorWithCodeFromResources("Touch.TimeSyntaxIncorrect", new object[] { exception.Message });
                return(false);
            }
            bool             flag = true;
            ArrayList        list = new ArrayList();
            HashSet <string> set  = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            foreach (ITaskItem item in this.Files)
            {
                if (!set.Contains(item.ItemSpec))
                {
                    if (this.TouchFile(item.ItemSpec, touchDateTime, fileExists, fileCreate, fileGetAttributes, fileSetAttributes, fileSetLastAccessTime, fileSetLastWriteTime))
                    {
                        list.Add(item);
                    }
                    else
                    {
                        flag = false;
                    }
                    set.Add(item.ItemSpec);
                }
            }
            this.TouchedFiles = (ITaskItem[])list.ToArray(typeof(ITaskItem));
            return(flag);
        }
Esempio n. 7
0
        /// <summary>
        /// Implementation of the execute method.
        /// </summary>
        /// <returns></returns>
        internal bool ExecuteImpl
        (
            FileExists fileExists,
            FileCreate fileCreate,
            GetAttributes fileGetAttributes,
            SetAttributes fileSetAttributes,
            SetLastAccessTime fileSetLastAccessTime,
            SetLastWriteTime fileSetLastWriteTime

        )
        {
            // See what time we are touching all files to
            DateTime touchDateTime;
            try
            {
                touchDateTime = GetTouchDateTime();
            }
            catch (FormatException e)
            {
                Log.LogErrorWithCodeFromResources("Touch.TimeSyntaxIncorrect", e.Message);
                return false;
            }

            // Go through all files and touch 'em
            bool retVal = true;
            ArrayList touchedItems = new ArrayList();
            HashSet<string> touchedFilesSet = new HashSet<string>(StringComparer.OrdinalIgnoreCase);

            foreach (ITaskItem file in Files)
            {
                // For speed, eliminate duplicates caused by poor targets authoring
                if (touchedFilesSet.Contains(file.ItemSpec))
                {
                    continue;
                }

                // Touch the file.  If the file was touched successfully then add it to our array of 
                // touched items. 
                if
                (
                    TouchFile
                    (
                        file.ItemSpec,
                        touchDateTime,
                        fileExists,
                        fileCreate,
                        fileGetAttributes,
                        fileSetAttributes,
                        fileSetLastAccessTime,
                        fileSetLastWriteTime

                    )
                )
                {
                    touchedItems.Add(file);
                }
                else
                {
                    retVal = false;
                }

                // Add even on failure to avoid reattempting
                touchedFilesSet.Add(file.ItemSpec);
            }

            // Now, set the property that indicates which items we touched.  Note that we
            // touch all the items 
            TouchedFiles = (ITaskItem[])touchedItems.ToArray(typeof(ITaskItem));
            return retVal;
        }
Esempio n. 8
0
        /// <summary>
        /// Helper method touches a file.
        /// </summary>
        /// <param name="file"></param>
        /// <param name="dt"></param>
        /// <param name="fileExists"></param>
        /// <param name="fileCreate"></param>
        /// <param name="fileGetAttributes"></param>
        /// <param name="fileSetAttributes"></param>
        /// <param name="fileSetLastAccessTime"></param>
        /// <param name="fileSetLastWriteTime"></param>
        /// <returns>"True" if the file was touched.</returns>
        private bool TouchFile
        (
            string file,
            DateTime dt,
            FileExists fileExists,
            FileCreate fileCreate,
            GetAttributes fileGetAttributes,
            SetAttributes fileSetAttributes,
            SetLastAccessTime fileSetLastAccessTime,
            SetLastWriteTime fileSetLastWriteTime
        )
        {
            if (!fileExists(file))
            {
                // If the file does not exist then we check if we need to create it.
                if (AlwaysCreate)
                {
                    Log.LogMessageFromResources(MessageImportance.Normal, "Touch.CreatingFile", file, "AlwaysCreate");
                    if (!CreateFile(file, fileCreate))
                    {
                        return false;
                    }
                }
                else
                {
                    Log.LogErrorWithCodeFromResources("Touch.FileDoesNotExist", file);
                    return false;
                }
            }
            else
            {
                Log.LogMessageFromResources(MessageImportance.Normal, "Touch.Touching", file);
            }

            // If the file is read only then we must either issue an error, or, if the user so 
            // specified, make the file temporarily not read only.
            bool needToRestoreAttributes = false;
            System.IO.FileAttributes faOriginal = fileGetAttributes(file);
            if ((faOriginal & System.IO.FileAttributes.ReadOnly) == System.IO.FileAttributes.ReadOnly)
            {
                if (ForceTouch)
                {
                    try
                    {
                        System.IO.FileAttributes faNew = (faOriginal & ~System.IO.FileAttributes.ReadOnly);
                        fileSetAttributes(file, faNew);
                        needToRestoreAttributes = true;
                    }
                    catch (Exception e) // Catching Exception, but rethrowing unless it's a well-known exception.
                    {
                        if (ExceptionHandling.NotExpectedException(e))
                            throw;
                        Log.LogErrorWithCodeFromResources("Touch.CannotMakeFileWritable", file, e.Message);
                        return false;
                    }
                }
            }

            // Do the actual touch operation
            bool retVal = true;
            try
            {
                fileSetLastAccessTime(file, dt);
                fileSetLastWriteTime(file, dt);
            }
            catch (Exception e) // Catching Exception, but rethrowing unless it's a well-known exception.
            {
                if (ExceptionHandling.NotExpectedException(e))
                    throw;
                Log.LogErrorWithCodeFromResources("Touch.CannotTouch", file, e.Message);
                return false;
            }
            finally
            {
                if (needToRestoreAttributes)
                {
                    // Attempt to restore the attributes.  If we fail here, then there is 
                    // not much we can do.
                    try
                    {
                        fileSetAttributes(file, faOriginal);
                    }
                    catch (Exception e) // Catching Exception, but rethrowing unless it's a well-known exception.
                    {
                        if (ExceptionHandling.NotExpectedException(e))
                            throw;
                        Log.LogErrorWithCodeFromResources("Touch.CannotRestoreAttributes", file, e.Message);
                        retVal = false;
                    }
                }
            }

            return retVal;
        }
Esempio n. 9
0
        private void GenCorrespondenceList(HttpContext context)
        {
            try
            {
                string GenFrom = ReadLastId();

                if (GenFrom == string.Empty)
                {
                    GenFrom = "400000";
                }

                string GenTo = context.Request.QueryString["SelectedItem"];

                try
                {
                    System.Xml.XmlDocument Doc  = new System.Xml.XmlDocument();
                    System.Xml.XmlDocument xDoc = new System.Xml.XmlDocument();

                    SDMService.USD_WebService ws = new SDMService.USD_WebService();
                    var      sid        = ws.login(Helpers.GetSetting("CALogin", false), Helpers.GetSetting("CAPassword", true));
                    var      handle     = ws.getHandleForUserid(sid, Helpers.GetSetting("CALogin", false));
                    String[] attributes = new string[] { "ref_num", "CorrespondanceLetterType.sym", "SenderEmployee.combo_name", "SenderOrganization.name", "Recipient.sym", "Street", "PostCode", "City", "Country", "OutcomeDate" };

                    var result = ws.doSelect(sid, "zCorrespondanceOucome", "id > " + GenFrom + " AND id <= " + GenTo, -1, attributes);

                    xDoc.LoadXml(result.ToString());

                    using (DocX document = DocX.Load(new FileStream(context.Server.MapPath(@"~/App_Data/template_karta_korespondencji_wychodzacej.docx"), FileMode.Open, FileAccess.Read)))
                    {
                        document.ReplaceText("<gen_date>", DateTime.Now.ToString("yyyy-dd-MM HH:mm"), false, RegexOptions.IgnoreCase);

                        Table ResultTable = document.AddTable(xDoc.GetElementsByTagName("Attributes").Count + 1, 10);
                        ResultTable.Alignment = Alignment.center;
                        ResultTable.Design    = TableDesign.LightShadingAccent3;
                        ResultTable.AutoFit   = AutoFit.Contents;

                        ResultTable.Rows[0].Cells[0].Paragraphs.First().Append("Ref").FontSize(8);
                        ResultTable.Rows[0].Cells[1].Paragraphs.First().Append("Rodzaj").FontSize(8);
                        ResultTable.Rows[0].Cells[2].Paragraphs.First().Append("Nadawca osoba").FontSize(8);
                        ResultTable.Rows[0].Cells[3].Paragraphs.First().Append("Nadawca org").FontSize(8);
                        ResultTable.Rows[0].Cells[4].Paragraphs.First().Append("Adresat").FontSize(8);
                        ResultTable.Rows[0].Cells[5].Paragraphs.First().Append("Ulica").FontSize(8);
                        ResultTable.Rows[0].Cells[6].Paragraphs.First().Append("Kod pocztowy").FontSize(8);
                        ResultTable.Rows[0].Cells[7].Paragraphs.First().Append("Miasto").FontSize(8);
                        ResultTable.Rows[0].Cells[8].Paragraphs.First().Append("Państwo").FontSize(8);
                        ResultTable.Rows[0].Cells[9].Paragraphs.First().Append("Data").FontSize(8);

                        int tRows  = 1;
                        int tCells = 0;
                        foreach (XmlElement GetAttributes in xDoc.GetElementsByTagName("Attributes"))
                        {
                            tCells = 0;
                            foreach (XmlElement Attribute in GetAttributes.GetElementsByTagName("Attribute"))
                            {
                                //string attrname = Attribute["AttrName"].InnerText;
                                if (Attribute["AttrName"].InnerText == "OutcomeDate")
                                {
                                    DateTime dt = UnixTimeStampToDateTime(Convert.ToDouble(Attribute["AttrValue"].InnerText));
                                    ResultTable.Rows[tRows].Cells[tCells].Paragraphs.First().Append(dt.ToString("yyyy-MM-dd HH:mm")).FontSize(8);
                                }
                                else
                                {
                                    ResultTable.Rows[tRows].Cells[tCells].Paragraphs.First().Append(Attribute["AttrValue"].InnerText).FontSize(8);
                                }

                                tCells++;
                            }
                            tRows++;
                        }

                        document.InsertTable(ResultTable);

                        document.ReplaceText("<item_count>", tRows.ToString(), false, RegexOptions.IgnoreCase);

                        System.IO.MemoryStream FileUploader = new MemoryStream();

                        document.SaveAs(FileUploader);

                        context.Response.Buffer = true;
                        context.Response.Clear();
                        context.Response.ContentType = "application/docx";
                        context.Response.AddHeader("content-disposition", "attachment; filename=" + string.Format("karta_korespondencji_wychodzacej_{0}.docx", DateTime.Now.ToString("yyyyMMdd_HHmm")));
                        context.Response.BinaryWrite(FileUploader.ToArray());
                        context.Response.Flush();
                        //context.Response.End();

                        FileUploader.Dispose();
                    }

                    ws.logout(sid);

                    SetLastId(GenTo);
                }
                catch (Exception ex)
                {
                    File.AppendAllText(System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath + "AppLog.log", "\r\n\r\nB" + DateTime.Now.ToString() + "\r\n" + ex.ToString());
                }
            }
            catch (Exception ex)
            {
                File.AppendAllText(System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath + "AppLog.log", "\r\n\r\nB" + DateTime.Now.ToString() + "\r\n" + ex.ToString());
            }
        }
 private bool TouchFile(string file, DateTime dt, Microsoft.Build.Shared.FileExists fileExists, Microsoft.Build.Shared.FileCreate fileCreate, GetAttributes fileGetAttributes, SetAttributes fileSetAttributes, SetLastAccessTime fileSetLastAccessTime, SetLastWriteTime fileSetLastWriteTime)
 {
     if (!fileExists(file))
     {
         if (!this.AlwaysCreate)
         {
             base.Log.LogErrorWithCodeFromResources("Touch.FileDoesNotExist", new object[] { file });
             return false;
         }
         base.Log.LogMessageFromResources(MessageImportance.Normal, "Touch.CreatingFile", new object[] { file, "AlwaysCreate" });
         if (!this.CreateFile(file, fileCreate))
         {
             return false;
         }
     }
     else
     {
         base.Log.LogMessageFromResources(MessageImportance.Normal, "Touch.Touching", new object[] { file });
     }
     bool flag = false;
     FileAttributes attributes = fileGetAttributes(file);
     if (((attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly) && this.ForceTouch)
     {
         try
         {
             FileAttributes attributes2 = attributes & ~FileAttributes.ReadOnly;
             fileSetAttributes(file, attributes2);
             flag = true;
         }
         catch (Exception exception)
         {
             if (Microsoft.Build.Shared.ExceptionHandling.NotExpectedException(exception))
             {
                 throw;
             }
             base.Log.LogErrorWithCodeFromResources("Touch.CannotMakeFileWritable", new object[] { file, exception.Message });
             return false;
         }
     }
     bool flag2 = true;
     try
     {
         fileSetLastAccessTime(file, dt);
         fileSetLastWriteTime(file, dt);
     }
     catch (Exception exception2)
     {
         if (Microsoft.Build.Shared.ExceptionHandling.NotExpectedException(exception2))
         {
             throw;
         }
         base.Log.LogErrorWithCodeFromResources("Touch.CannotTouch", new object[] { file, exception2.Message });
         return false;
     }
     finally
     {
         if (flag)
         {
             try
             {
                 fileSetAttributes(file, attributes);
             }
             catch (Exception exception3)
             {
                 if (Microsoft.Build.Shared.ExceptionHandling.NotExpectedException(exception3))
                 {
                     throw;
                 }
                 base.Log.LogErrorWithCodeFromResources("Touch.CannotRestoreAttributes", new object[] { file, exception3.Message });
                 flag2 = false;
             }
         }
     }
     return flag2;
 }