Пример #1
0
        void AddEvent(Event e, bool select = false)
        {
            Controls.Event ev = CreateEvent(e);

            var event_bt = new Controls.EventButton();

            event_bt.EventName       = String_Functions.UppercaseFirst(e.name.Replace('_', ' '));
            event_bt.SettingChanged += event_bt_SettingChanged;
            event_bt.RemoveClicked  += Event_RemoveClicked;
            event_bt.ParentEvent     = e;

            var bt = new TrakHound_UI.CollapseButton();

            bt.ButtonContent = event_bt;

            if (select)
            {
                event_bt.eventname_TXT.Focus();

                foreach (var obt in EventButtons)
                {
                    obt.IsExpanded = false;
                }
                bt.IsExpanded = true;
            }

            bt.PageContent = ev;

            events.Add(ev);

            EventButtons.Add(bt);
        }
Пример #2
0
        public void SaveConfiguration(DataTable dt)
        {
            string prefix = "/GeneratedData/SnapShotData/";

            // Clear all snapshot rows first (so that Ids can be sequentially assigned)
            DataTable_Functions.TrakHound.DeleteRows(prefix + "*", "address", dt);

            // Loop through SnapshotItems and add each item back to table with sequential id's
            foreach (var item in SnapshotItems)
            {
                if (item.ParentSnapshot != null)
                {
                    var snapshot = item.ParentSnapshot;

                    if (snapshot.Name != null && snapshot.Link != null)
                    {
                        string adr = "/GeneratedData/SnapShotData/" + String_Functions.UppercaseFirst(snapshot.Type.ToString().ToLower());
                        int    id  = DataTable_Functions.TrakHound.GetUnusedAddressId(adr, dt);
                        adr = adr + "||" + id.ToString("00");

                        string attr = "";
                        attr += "id||" + id.ToString("00") + ";";
                        attr += "name||" + snapshot.Name + ";";

                        string link = snapshot.Link;

                        attr += "link||" + link + ";";

                        DataTable_Functions.UpdateTableValue(dt, "address", adr, "attributes", attr);
                    }
                }
            }
        }
Пример #3
0
        public void Login(ServerCredentials.LoginData loginData)
        {
            UserConfiguration userConfig = null;

            if (loginData != null)
            {
                while (loginData != null && userConfig == null)
                {
                    userConfig = UserManagement.TokenLogin(loginData.Token);
                    if (userConfig == null)
                    {
                        logger.Warn(String_Functions.UppercaseFirst(loginData.Username) + " Failed to Login... Retrying in 5 seconds");

                        Thread.Sleep(5000);

                        loginData = ServerCredentials.Read();
                    }
                }

                if (userConfig != null)
                {
                    logger.Info(String_Functions.UppercaseFirst(userConfig.Username) + " Logged in Successfully");
                }
            }

            CurrentUser = userConfig;
        }
Пример #4
0
        private void Init()
        {
            InitializeComponent();
            root.DataContext = this;

            Id = String_Functions.RandomString(20);
        }
        void UploadProfileImage(EditUserInfo info, string path)
        {
            if (path != null)
            {
                // Crop and Resize image
                System.Drawing.Image img = ProcessImage(path);
                if (img != null)
                {
                    // Generate random file name for processed/temp image (to be saved in temp folder)
                    string newFilename = String_Functions.RandomString(20);

                    // Get file extension of original file
                    string ext = Path.GetExtension(path);

                    // Make sure Temp directory exists
                    FileLocations.CreateTempDirectory();

                    // Create new full path of temp file
                    string localPath = Path.Combine(FileLocations.TrakHoundTemp, newFilename);
                    //if (ext != null) localPath += "." + ext;
                    if (ext != null)
                    {
                        localPath = Path.ChangeExtension(localPath, ext);
                    }

                    // Save the processed image to the new temp path
                    img.Save(localPath);

                    // Create a temp UserConfiguration object to pass the current SessionToken to the Files.Upload() method
                    var userConfig = new UserConfiguration();
                    userConfig.SessionToken = info.SessionToken;

                    // Set the HTTP Content Type based on the type of image
                    string contentType = null;
                    if (ext == "jpg")
                    {
                        contentType = "image/jpeg";
                    }
                    else if (ext == "png")
                    {
                        contentType = "image/png";
                    }
                    else if (ext == "gif")
                    {
                        contentType = "image/gif";
                    }

                    var fileData = new HTTP.FileContentData("uploadimage", localPath, contentType);

                    // Upload File
                    var uploadInfos = TrakHound.API.Files.Upload(userConfig, fileData);
                    if (uploadInfos != null && uploadInfos.Length > 0)
                    {
                        string fileId = uploadInfos[0].Id;

                        info.ImageUrl = fileId;
                    }
                }
            }
        }
        public static string CreateTempPath()
        {
            CreateTempDirectory();

            string filename = String_Functions.RandomString(20);

            return(Path.Combine(TrakHoundTemp, filename));
        }
Пример #7
0
        public void Login(UserConfiguration userConfig)
        {
            CurrentUser = userConfig;

            if (userConfig != null)
            {
                logger.Info(String_Functions.UppercaseFirst(userConfig.Username) + " Logged in Successfully");
            }
        }
Пример #8
0
 private void LoadProbeHeader(MTConnect.Headers.MTConnectDevicesHeader header)
 {
     InstanceId      = header.InstanceId.ToString();
     Sender          = header.Sender;
     Version         = header.Version;
     BufferSize      = String_Functions.FileSizeSuffix(header.BufferSize);
     AssetBufferSize = String_Functions.FileSizeSuffix(header.AssetBufferSize);
     AssetCount      = header.AssetCount.ToString();
 }
Пример #9
0
 private static void ConvertRowFromSafe(DataRow row)
 {
     for (var x = 0; x <= row.ItemArray.Length - 1; x++)
     {
         if (row.Table.Columns[x].DataType == typeof(string))
         {
             row[x] = String_Functions.FromSpecial(row.ItemArray[x].ToString());
         }
     }
 }
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value != null)
            {
                string val = value.ToString();

                return(String_Functions.UppercaseFirst(val));
            }

            return(null);
        }
Пример #11
0
 private string GetFormattedValue(string s)
 {
     if (!string.IsNullOrEmpty(s))
     {
         return(String_Functions.UppercaseFirst(s.Replace('_', ' ')));
     }
     else
     {
         return(null);
     }
 }
Пример #12
0
        private void ProcessGeneratedEvents(EventData data)
        {
            var gEventItems = (List <GeneratedEvent>)data.Data02;

            gEventItems = gEventItems.OrderBy(o => o.CurrentValue.Timestamp).ToList();

            var pc = Configuration.Get(configuration);

            if (pc != null)
            {
                var infos = new List <PartInfo>();

                foreach (var partCountEvent in pc.Events)
                {
                    var matchedItems = gEventItems.FindAll(x => x.EventName == partCountEvent.EventName && x.CurrentValue != null && x.PreviousValue != null);
                    foreach (var gEvent in matchedItems)
                    {
                        // Test if current event value matches configured EventName
                        if (gEvent.CurrentValue != null && gEvent.CurrentValue.Value == String_Functions.UppercaseFirst(partCountEvent.EventValue.Replace('_', ' ')))
                        {
                            bool match = true;

                            // Test if previous event value matches configured PreviousEventName
                            if (!string.IsNullOrEmpty(partCountEvent.PreviousEventValue))
                            {
                                match = gEvent.PreviousValue.Value == String_Functions.UppercaseFirst(partCountEvent.PreviousEventValue.Replace('_', ' '));
                            }

                            if (match)
                            {
                                lock (_lock)
                                {
                                    var partInfo = PartInfo.Process(partCountEvent, gEvent, lastSequence);
                                    if (partInfo != null)
                                    {
                                        infos.Add(partInfo);

                                        lastSequence = partInfo.Sequence;
                                        SaveStoredSequence(configuration, lastSequence);
                                    }
                                }
                            }
                        }
                    }

                    if (infos.Count > 0)
                    {
                        SendPartInfos(infos);
                    }
                }
            }
        }
Пример #13
0
        public void Login(string username, string password)
        {
            Loading        = true;
            LoadingMessage = String_Functions.UppercaseFirst(username);
            LoginError     = false;

            Login_Info info = new Login_Info();

            info.Username = username;
            info.Password = password;

            ThreadPool.QueueUserWorkItem(new WaitCallback(Login_Worker), info);
        }
Пример #14
0
        /// <summary>
        /// Convert from 'first_second_third' to 'FirstSecondThird'
        /// </summary>
        /// <param name="var"></param>
        /// <returns></returns>
        private static string FromJsonVariable(string var)
        {
            var builder = new StringBuilder();

            string[] words = var.Split('_');

            string s;

            foreach (string word in words)
            {
                s = String_Functions.UppercaseFirst(word);
                builder.Append(s);
            }

            return(builder.ToString());
        }
        public void LoadUserConfiguration(UserConfiguration userConfig)
        {
            CurrentUser = userConfig;

            profileImageLoaded = false;

            SetPageType(userConfig);

            if (userConfig != null)
            {
                UsernameVerified = true;

                FirstName = String_Functions.UppercaseFirst(userConfig.FirstName);
                LastName  = String_Functions.UppercaseFirst(userConfig.LastName);

                Username = String_Functions.UppercaseFirst(userConfig.Username);
                Email    = userConfig.Email;

                Company  = String_Functions.UppercaseFirst(userConfig.Company);
                Phone    = userConfig.Phone;
                Address1 = userConfig.Address1;
                Address2 = userConfig.Address2;
                City     = userConfig.City;
                ZipCode  = userConfig.Zipcode;

                int country = CountryList.ToList().FindIndex(x => x == String_Functions.UppercaseFirst(userConfig.Country));
                if (country >= 0)
                {
                    country_COMBO.SelectedIndex = country;
                }

                int state = CountryList.ToList().FindIndex(x => x == String_Functions.UppercaseFirst(userConfig.State));
                if (state >= 0)
                {
                    state_COMBO.SelectedIndex = state;
                }

                LoadProfileImage(userConfig);
            }
            else
            {
                CleanForm();
            }
        }
Пример #16
0
        Controls.CaptureItem CreateCaptureItem(CaptureItem ci, Event e)
        {
            Controls.CaptureItem result = new Controls.CaptureItem();

            result.ParentPage        = this;
            result.ParentEvent       = e;
            result.ParentCaptureItem = ci;

            result.SettingChanged += CaptureItem_SettingChanged;
            result.RemoveClicked  += CaptureItem_RemoveClicked;

            if (ci.name != null)
            {
                result.CaptureName = String_Functions.UppercaseFirst(ci.name.Replace('_', ' '));
            }

            result.link_COMBO.Text = ci.link;

            return(result);
        }
 public CaptureItem(GeneratedEvents.Page.CaptureItem item)
 {
     Id   = item.name;
     Name = String_Functions.UppercaseFirst(item.name.Replace('_', ' '));
 }
Пример #18
0
        private static ResponseInfo SendData(
            bool returnBytes,
            string method,
            string url,
            PostContentData[] postDatas  = null,
            FileContentData[] fileDatas  = null,
            HeaderData[] headers         = null,
            string userAgent             = null,
            NetworkCredential credential = null,
            ProxySettings proxySettings  = null,
            int timeout      = TIMEOUT,
            int maxAttempts  = CONNECTION_ATTEMPTS,
            bool getResponse = true
            )
        {
            ResponseInfo result = null;

            int    attempts = 0;
            bool   success  = false;
            string message  = null;

            // Try to send data for number of connectionAttempts
            while (attempts < maxAttempts && !success)
            {
                attempts += 1;

                try
                {
                    // Create HTTP request and define Header info
                    var request = (HttpWebRequest)WebRequest.Create(url);

                    string boundary = String_Functions.RandomString(10);

                    request.Timeout          = timeout;
                    request.ReadWriteTimeout = timeout;
                    if (method == "POST")
                    {
                        request.ContentType = "multipart/form-data; boundary=" + boundary;
                    }
                    else
                    {
                        request.ContentType = "application/x-www-form-urlencoded";
                    }


                    // Set the Method
                    request.Method = method;

                    // Set the UserAgent
                    if (userAgent != null)
                    {
                        request.UserAgent = userAgent;
                    }
                    else
                    {
                        request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; Windows NT 5.2; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
                    }

                    // Add Header data to request stream (if present)
                    if (headers != null)
                    {
                        foreach (var header in headers)
                        {
                            request.Headers[header.Id] = header.Text;
                        }
                    }

                    // set NetworkCredentials
                    if (credential != null)
                    {
                        request.Credentials     = credential;
                        request.PreAuthenticate = true;
                    }

                    // Get Default System Proxy (Windows Internet Settings -> Proxy Settings)
                    var proxy = WebRequest.GetSystemWebProxy();

                    // Get Custom Proxy Settings from Argument (overwrite default proxy settings)
                    if (proxySettings != null)
                    {
                        if (proxySettings.Address != null && proxySettings.Port > 0)
                        {
                            var customProxy = new WebProxy(proxySettings.Address, proxySettings.Port);
                            customProxy.BypassProxyOnLocal = false;
                            proxy = customProxy;
                        }
                    }

                    request.Proxy = proxy;

                    var bytes = new List <byte>();

                    // Add Post Name/Value Pairs
                    if (postDatas != null)
                    {
                        string formdataTemplate = "Content-Disposition: form-data; name=\"{0}\"\r\n\r\n{1}";

                        foreach (var postData in postDatas)
                        {
                            string formitem = string.Format(formdataTemplate, postData.Name, postData.Value);

                            bytes.AddRange(GetBytes("\r\n--" + boundary + "\r\n"));
                            bytes.AddRange(GetBytes(formitem));
                        }
                    }

                    // Add File data
                    if (fileDatas != null)
                    {
                        bytes.AddRange(GetFileContents(fileDatas, boundary));
                    }

                    if (bytes.Count > 0)
                    {
                        // Write Trailer Boundary
                        string trailer = "\r\n--" + boundary + "--\r\n";
                        bytes.AddRange(GetBytes(trailer));

                        var byteArray = bytes.ToArray();

                        // Write Data to Request Stream
                        request.ContentLength = byteArray.Length;

                        using (var requestStream = request.GetRequestStream())
                        {
                            requestStream.Write(byteArray, 0, byteArray.Length);
                        }
                    }

                    // Get Response Message from HTTP Request
                    if (getResponse)
                    {
                        result = new ResponseInfo();

                        using (var response = (HttpWebResponse)request.GetResponse())
                        {
                            // Get HTTP Response Body
                            using (var responseStream = response.GetResponseStream())
                                using (var memStream = new MemoryStream())
                                {
                                    byte[] buffer = new byte[10240];

                                    int read;
                                    while ((read = responseStream.Read(buffer, 0, buffer.Length)) > 0)
                                    {
                                        memStream.Write(buffer, 0, read);
                                    }

                                    result.Body = memStream.ToArray();

                                    success = true;
                                }

                            var responseHeaders = new List <ReponseHeaderInfo>();

                            // Get HTTP Response Headers
                            foreach (var key in response.Headers.AllKeys)
                            {
                                var header = new ReponseHeaderInfo();
                                header.Key   = key;
                                header.Value = response.Headers.Get(key);

                                responseHeaders.Add(header);
                            }

                            result.Headers = responseHeaders.ToArray();
                        }
                    }
                    else
                    {
                        success = true;
                    }
                }
                catch (WebException wex) { message = wex.Message; }
                catch (Exception ex) { message = ex.Message; }

                if (!success)
                {
                    System.Threading.Thread.Sleep(500);
                }
            }

            if (!success)
            {
                logger.Info("Send :: " + attempts.ToString() + " Attempts :: URL = " + url + " :: " + message);
            }

            return(result);
        }
Пример #19
0
 public override string ToString()
 {
     return(String_Functions.UppercaseFirst(name.Replace('_', ' ')));
 }
Пример #20
0
        private void UploadDeviceImage_Worker(object o)
        {
            if (o != null)
            {
                var info = (ImageInfo)o;

                string fileId = null;

                if (info.UserConfig != null)
                {
                    string contentType = null;

                    try
                    {
                        string ext = Path.GetExtension(info.FileId);

                        if (ext == "jpg" || ext == ".jpg")
                        {
                            contentType = "image/jpeg";
                        }
                        else if (ext == "png" || ext == ".png")
                        {
                            contentType = "image/png";
                        }
                        else if (ext == "gif" || ext == ".gif")
                        {
                            contentType = "image/gif";
                        }

                        var img = System.Drawing.Image.FromFile(info.FileId);
                        if (img != null)
                        {
                            if (img.Width > img.Height)
                            {
                                img = Image_Functions.SetImageSize(img, 300, 300);
                            }
                            else
                            {
                                img = Image_Functions.SetImageSize(img, 0, 150);
                            }

                            string tempPath = Path.ChangeExtension(String_Functions.RandomString(20), ext);
                            tempPath = Path.Combine(FileLocations.TrakHoundTemp, tempPath);

                            // Make sure Temp directory exists
                            FileLocations.CreateTempDirectory();

                            img.Save(tempPath);
                            img.Dispose();

                            var fileData = new HTTP.FileContentData("uploadImage", tempPath, contentType);

                            var fileInfos = Files.Upload(currentUser, fileData);
                            if (fileInfos != null && fileInfos.Length > 0)
                            {
                                fileId = fileInfos[0].Id;
                            }
                        }
                    }
                    catch (Exception ex) { logger.Error(ex); }
                }
                else
                {
                    string filename = Path.ChangeExtension(Guid.NewGuid().ToString(), ".image");

                    string destinationPath = Path.Combine(FileLocations.Storage, filename);

                    FileLocations.CreateStorageDirectory();

                    File.Copy(info.FileId, destinationPath);

                    fileId = filename;
                }

                Dispatcher.BeginInvoke(new Action <string>(UploadDeviceImage_GUI), System.Windows.Threading.DispatcherPriority.Background, new object[] { fileId });
            }
        }
Пример #21
0
 public GeneratedEventItem(TrakHound_Dashboard.Pages.DeviceManager.Pages.GeneratedEvents.Page.Event e)
 {
     Id    = e.name;
     Name  = String_Functions.UppercaseFirst(e.name.Replace('_', ' ').ToLower());
     Event = e;
 }
Пример #22
0
 public GeneratedEventItem(GeneratedEvents.Page.Event e)
 {
     Id    = e.name;
     Name  = String_Functions.UppercaseFirst(e.name.Replace('_', ' ').ToLower());
     Event = e;
 }